Curl_Multi Infinite Loop (10mn)

153 views Asked by At

I have a problem with this function:

function multi_activity($nodes,$headers){

$node_count = count($nodes);
$results=array();
$curl_arr = array();
$master = curl_multi_init();

for($i = 0; $i < $node_count; $i++)
{
    $url =$nodes[$i];
    $curl_arr[$i] = curl_init($url);
    curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl_arr[$i], CURLOPT_HEADER, false);
    curl_setopt($curl_arr[$i], CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl_arr[$i], CURLOPT_FOLLOWLOCATION, false);
    curl_setopt($curl_arr[$i], CURLOPT_SSL_VERIFYPEER, false);
    curl_multi_add_handle($master, $curl_arr[$i]);
}    
  do {       
    curl_multi_exec($master,$running);  
    } while($running > 0 );  


for($i = 0; $i < $node_count; $i++)
{

    $results[] = curl_multi_getcontent  ( $curl_arr[$i]  );
    curl_multi_remove_handle($master, $curl_arr[$i]);

}   
curl_multi_close($master);
return $results;
}

Actually, I'm calling this function 300 times and each time with a $nodes containing 30 different URLs. I don't actually understand How CUrl actually works But I have to wait for 10mn to get the job done and to print my JSON. Is there a way to improve it by using multi_curl or an other asynchronous PHP tool/API. Thanks in advance.

0

There are 0 answers