curl_multi_exec如何在多个IP地址上执行它并获取响应标头
你好,我已经在一个IP上做了一个curl测试,我可以获得响应信息(时间,响应代码,...) 这次我想让它同时在多个IP上运行。我发现这可以通过curl_multi_exec实现,并且我发现了这段代码:
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();
// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);
//create the multiple cURL handle
$mh = curl_multi_init();
//add the two handles
curl_multi_add_handle($mh, $ch1);
curl_multi_add_handle($mh, $ch2);
$running = null;
//execute the handles
do {
curl_multi_exec($mh, $running);
} while ($running > 0);
//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);
但我只得到最后输入的url的洞内容(CURLOPT_URL,“http://www.php.net/”) 此外,我想要有关请求和响应的信息(在curl中我使用了 ($infos = curl_getinfo($curl);)
Hello i have made a curl test on an ip and i could get the response infos( times, response code,...)
this time i want to make it work on several ip's in the same time. I found that could be possible with curl_multi_exec, and i found this code:
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();
// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);
//create the multiple cURL handle
$mh = curl_multi_init();
//add the two handles
curl_multi_add_handle($mh, $ch1);
curl_multi_add_handle($mh, $ch2);
$running = null;
//execute the handles
do {
curl_multi_exec($mh, $running);
} while ($running > 0);
//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);
But i only get the hole content of the last url entered (CURLOPT_URL, "http://www.php.net/")
and besides, i want the informations abouts the request and response( in curl i used ($infos = curl_getinfo($curl);)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要 具有多线程的 PHP cURL 类
在这里获取它 http://pastebin.com/vBgYDzVu 或在这里 http://semlabs.co.uk/assets/files/curl.zip
例如:
You probably need PHP cURL Class With Multi-Threading
Get it here http://pastebin.com/vBgYDzVu or here http://semlabs.co.uk/assets/files/curl.zip
Ex: