Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 对同一url的多个curl调用_Php_Curl - Fatal编程技术网

Php 对同一url的多个curl调用

Php 对同一url的多个curl调用,php,curl,Php,Curl,我想建立点击引擎,模拟用户点击特定Url, 我在循环中使用curl\u exec调用相同的url 如何提高此脚本的性能? 正确的方法是什么? 到目前为止,我所做的是: $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => true, // return headers CURLOPT_FOLLOWLOCATION =>

我想建立点击引擎,模拟用户点击特定Url, 我在循环中使用
curl\u exec
调用相同的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);
 ...      
}
$options=数组(
CURLOPT_RETURNTRANSFER=>true,//返回网页
CURLOPT_头=>true,//返回头
CURLOPT_FOLLOWLOCATION=>true,//跟随重定向
CURLOPT_ENCODING=>“”,//处理所有编码
CURLOPT_USERAGENT=>$USERAGENT,//我是谁
CURLOPT_AUTOREFERER=>true,//在重定向时设置referer
CURLOPT_CONNECTTIMEOUT=>120,//连接超时
CURLOPT_TIMEOUT=>120,//响应超时
CURLOPT_MAXREDIRS=>1,//在1重定向后停止
CURLOPT_URL=>$URL.$fields_字符串,
CURLOPT_SSL_VERIFYPEER=>false,
); 
//开放连接
$ch=curl_init();
对于($i=0;$i<$NumberOfHits;$i++)
{        
curl_setopt_数组($ch$options);
//执行职务
$result=curl\u exec($ch);
if(旋度误差($ch))
{
$error=“Curl error:”.Curl\u error($ch)。“\n”;
fwrite($fp,$error);
}
$returnCode=curl\u getinfo($ch);
$my_arr[]=parse_url($returnCode['url'],PHP_url\u QUERY);
...      
}

我知道curl\u multi\u exec,但这个问题是针对不同的URL构建的,在我的情况下也使用它是否正确?

您需要多高的性能?你也可以通过使用
的普通curL_exec来实现这一点,而
,我尝试过,它能够在一秒钟内完成大约5次点击,因此一分钟内可以完成300次点击。尽管这可能取决于您的isp。

您需要多高的性能?你也可以通过使用
的普通curL_exec来实现这一点,而
,我尝试过,它能够在一秒钟内完成大约5次点击,因此一分钟内可以完成300次点击。尽管这可能取决于您的isp