Advertisement
Guest User

Benchmark for file_get_contents

a guest
Dec 14th, 2010
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. <?php
  2. require "benchmark.php"; // http://pastebin.com/Jad5TjsQ
  3.  
  4. function FGC($url, $post = null, $retries = 3)
  5. {
  6.     global $errors;
  7.     $http = array
  8.     (
  9.         'method' => 'GET',
  10.     );
  11.  
  12.     if (isset($post) === true)
  13.     {
  14.         $http['method'] = 'POST';
  15.         $http['header'] = 'Content-Type: application/x-www-form-urlencoded';
  16.         $http['content'] = (is_array($post) === true) ? http_build_query($post, '', '&') : $post;
  17.     }
  18.  
  19.     $result = false;
  20.  
  21.     while (($result === false) && (--$retries > 0))
  22.     {
  23.         try
  24.         {
  25.             $result = file_get_contents($url, false, stream_context_create(array('http' => $http)));
  26.         }
  27.         catch(Exception $e)
  28.         {
  29.             $errors["FGC"]++;
  30.         }
  31.     }
  32.  
  33.     return $result;
  34. }
  35.  
  36. $result = array();
  37. $result[10000]['FGC'] = Benchmark('FGC', 'http://wizcorp.mt.dev.wizcorp.jp/', 10000);
  38. print_r($errors);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement