Advertisement
Guest User

Benchmark for cURL

a guest
Dec 14th, 2010
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. <?php
  2. require "benchmark.php"; // http://pastebin.com/Jad5TjsQ
  3.  
  4. function CURL($url, $post = null, $retries = 2)
  5. {
  6.     global $errors;
  7.     $curl = curl_init($url);
  8.  
  9.     if (is_resource($curl) === true)
  10.     {
  11.         curl_setopt($curl, CURLOPT_FAILONERROR, true);
  12.         curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  13.         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  14.         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  15.         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  16.  
  17.         if (isset($post) === true)
  18.         {
  19.             curl_setopt($curl, CURLOPT_POST, true);
  20.             curl_setopt($curl, CURLOPT_POSTFIELDS, (is_array($post) === true) ? http_build_query($post, '', '&') : $post);
  21.         }
  22.  
  23.         $result = false;
  24.  
  25.         while (($result === false) && (--$retries > 0))
  26.         {
  27.             $result = curl_exec($curl);
  28.             if($result == FALSE)
  29.                 $errors["cURL"]++;
  30.         }
  31.  
  32.         curl_close($curl);
  33.     }
  34.  
  35.     return $result;
  36. }
  37.  
  38. $result = array();
  39. $result[10000]['CURL'] = Benchmark('CURL', 'http://wizcorp.mt.dev.wizcorp.jp/', 10000);
  40. print_r($errors);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement