I am trying to do curl_muliti_*
, but I am having issues, and I don't know what is causing the problem. When I run the following code, I get stuck in an infinite loop here 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);
}
}
in the loop (above the if) I add var_dump(curl_multi_select($mh))
and it outputs int(-1)
Why is it doing that?
Here is the full method:
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;
}
Note: Let me know what other code you may need.