php curl 并发
程序员文章站
2022-05-05 20:39:09
...
本文讲述的是curl并发访问url,无返回结果,单纯的访问url,若要返回结果,参考原文
public function curlauto(){
$accountlist= "account list";
$queue = curl_multi_init();
$map = array();
$url = "http://my url/id/";
foreach ($accountlist as $account) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url.$account['id']);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_NOSIGNAL, true);
curl_multi_add_handle($queue, $ch);
$map[(string) $ch] = $url;
}
do {
while (($code = curl_multi_exec($queue, $active)) == CURLM_CALL_MULTI_PERFORM) ;
if ($code != CURLM_OK) { break; }
while ($done = curl_multi_info_read($queue)) {
curl_multi_remove_handle($queue, $done['handle']);
curl_close($done['handle']);
}
if ($active > 0) {
curl_multi_select($queue, 0.5);
}
} while ($active);
curl_multi_close($queue);
}
原文地址;https://www.oschina.net/question/54100_58279
上一篇: 通过URL获取网络资源
下一篇: 商业项目中代码质量是否重要?