我正在尝试curl_muliti_*
,但我遇到了问题,而且我不知道导致问题的原因。当我运行以下代码时,我陷入了无限循环while($active && $mrc === CURLM_OK){
$active = null;
do{
$mrc = curl_multi_exec($mh, $active);
}while($mrc === CURLM_CALL_MULTI_PERFORM);
while($active && $mrc === CURLM_OK){
if(curl_multi_select($mh) !== -1){
do{
$mrc = curl_multi_exec($mh, $active);
}while($mrc === CURLM_CALL_MULTI_PERFORM);
}
}
在循环中(在if之上)我添加var_dump(curl_multi_select($mh))
并输出int(-1)
为什么这样做?
以下是完整的方法:
protected function getURLs($other_params = array()){
$url = $this->url;
$url_list = array();
if(!is_array($url)){
return false;
}
$mh = curl_multi_init();
foreach($url as $u){
$url_list[] = $handle = $this->curlInit($u, $other_params);
curl_multi_add_handle($mh, $handle);
}
$active = null;
do{
$mrc = curl_multi_exec($mh, $active);
}while($mrc === CURLM_CALL_MULTI_PERFORM);
while($active && $mrc === CURLM_OK){
if(curl_multi_select($mh) !== -1){
do{
$mrc = curl_multi_exec($mh, $active);
}while($mrc === CURLM_CALL_MULTI_PERFORM);
}
}
$data = array();
foreach($url_list as $handle){
$data[] = curl_multi_getcontent($handle);
curl_multi_remove_handle($mh, $handle);
}
curl_multi_close($mh);
return $data;
}
注意:请告诉我您可能需要的其他代码。