栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

php multi curl

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

php multi curl

function multiCurl($res,$options=""){ 

if(count($res)<=0) return False; 

$handles = array(); 

if(!$options) // add default options 

$options = array( 

CURLOPT_HEADER=>0, 

CURLOPT_RETURNTRANSFER=>1, 

); 

// add curl options to each handle 

foreach($res as $k=>$row){ 

$ch{$k} = curl_init(); 

$options[CURLOPT_URL] = $row['url']; 

curl_setopt_array($ch{$k}, $options); 

$handles[$k] = $ch{$k}; 

$mh = curl_multi_init(); 

foreach($handles as $k => $handle){ 

curl_multi_add_handle($mh,$handle); 

//echo "
adding handle {$k}"; 

$running_handles = null; 

//execute the handles 

$cme=null;

$status=null;

do { 

$status_cme = curl_multi_exec($mh, $running_handles); 

} while ($cme == CURLM_CALL_MULTI_PERFORM); 

while ($running_handles && $status_cme == CURLM_OK) { 

if (curl_multi_select($mh) != -1) { 

do { 

$status_cme = curl_multi_exec($mh, $running_handles); 

// echo "
''threads'' running = {$running_handles}"; 

} while ($status == CURLM_CALL_MULTI_PERFORM); 

foreach($res as $k=>$row){ 

$res[$k]['error'] = curl_error($handles[$k]); 

if(!empty($res[$k]['error'])) 

$res[$k]['data']  = ''; 

else 

$res[$k]['data']  = curl_multi_getcontent( $handles[$k] );  // get results 

// close current handler 

curl_multi_remove_handle($mh, $handles[$k] ); 

curl_multi_close($mh); 

return $res; // return response 

$res = array( 

"11"=>array("url"=>"http://api.211.100.56.140.xip.io/shows.json/263?appKey=strKfLS2Hecp"), 

"12"=>array("url"=>"http://api.211.100.56.140.xip.io/shows.json/263?appKey=strKfLS2Hecp"), 

); 

print_r(multiCurl($res)); 

?>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/230017.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号