1
我想建立匹配引擎,模擬用戶點擊到特定的URL, 我在一個循環中使用curl_exec
調用相同的URL。多個捲曲調用相同的URL
如何提高此腳本的性能?
什麼是正確的方法來做到這一點?
我做什麼,到現在爲止是:
$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);
...
}
我知道curl_multi_exec但這個問題是要建立不同的URL,那會是正確的在我的情況下使用它呢?