How to use curl_multi_info_read() to get information about the current transfers in PHP

1 Answer

0 votes
$urls = array(
   "http://www.collectivesolver.com/",
   "http://www.buyfrompictures.com/",
   "http://www.php.net/"
);

$cumh = curl_multi_init();

foreach ($urls as $i => $url) 
{
    $con[$i] = curl_init($url);
    curl_setopt($con[$i], CURLOPT_RETURNTRANSFER, 1);
    curl_multi_add_handle($cumh, $con[$i]);
}

$exc = null;
do 
{
    $status = curl_multi_exec($cumh, $exc);
    $info = curl_multi_info_read($cumh);
    if ($info !== false) 
        var_dump($info);
} while ($status === CURLM_CALL_MULTI_PERFORM || $exc);

foreach ($urls as $i => $url) 
{
    $content[$i] = curl_multi_getcontent($con[$i]);
    curl_close($con[$i]);
}

echo "<pre>";
print_r(curl_multi_info_read($cumh));
echo "</pre>";



/*
run: 

array(3) { ["msg"]=> int(1) ["result"]=> int(0) ["handle"]=> resource(5) of type (curl) } 
array(3) { ["msg"]=> int(1) ["result"]=> int(0) ["handle"]=> resource(3) of type (curl) } 
array(3) { ["msg"]=> int(1) ["result"]=> int(0) ["handle"]=> resource(4) of type (curl) } 

*/

 



answered Jun 8, 2016 by avibootz
...