tags:

views:

33

answers:

0

I want to build hits engine that simulate users hits to specific Url, I use curl_exec call to the same url in a loop.

How can I improve the performance of this script ?

What is the right way to do this ?

What i do until now is :

$options = array( 
 CURLOPT_RETURNTRANSFER => true,     // return web page 
 CURLOPT_HEADER         => true,    // return headers 
 CURLOPT_FOLLOWLOCATION => true,     // follow redirects 
 CURLOPT_ENCODING       => "",       // handle all encodings 
 CURLOPT_USERAGENT      => $useragent, // who am i 
 CURLOPT_AUTOREFERER    => true,     // set referer on redirect 
 CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect 
 CURLOPT_TIMEOUT        => 120,      // timeout on response 
 CURLOPT_MAXREDIRS      => 1,       // stop after 1 redirects 
 CURLOPT_URL            => $url . $fields_string,
 CURLOPT_SSL_VERIFYPEER => false,  
); 

//open connection
$ch = curl_init();

for ($i = 0; $i < $NumberOfHits; $i++)
{        
 curl_setopt_array($ch, $options);
 //execute post
 $result = curl_exec($ch);
 if(curl_errno($ch))
 {
    $error = "Curl error: " . curl_error($ch) . "\n";
    fwrite($fp, $error);
 }
 $returnCode = curl_getinfo($ch);     
 $my_arr[] = parse_url($returnCode['url'] , PHP_URL_QUERY);
 ...      
}

I know about curl_multi_exec but this issue is build to different urls, Would it be right to use it in my case too ?