/**
* curl并发请求
*
* @since 2016-12-30
* @author mingazi@163.com
* @param array $queryArr 查询数组
* string $url 地址url
* array $param 查询参数
* @return array $result 返回数据
*/
function curlMultiRequest ($queryArr)
{
$ch = curl_multi_init();
$chArr = array();
$results = array(); // 返回数组
foreach ($queryArr as $k => $v)
{
$chArr[$k] = curl_init($v['url']);
curl_setopt($chArr[$k],CURLOPT_POST,true);
curl_setopt($chArr[$k],CURLOPT_POSTFIELDS,http_build_query($v['param']));
curl_setopt($chArr[$k], CURLOPT_RETURNTRANSFER, true);
curl_multi_add_handle($ch, $chArr[$k]);
}
$running = null;
do
{
curl_multi_exec($ch, $running);
} while ($running > 0);
foreach( $queryArr as $k => $v)
{
$results[$k] = curl_multi_getcontent($chArr[$k]);
curl_multi_remove_handle($ch, $chArr[$k]);
}
curl_multi_close($ch);
return $results;
}
转载于:https://my.oschina.net/helloworldcoding/blog/817818