Run parallel handler of curl with curl_multi_exec

692 Views Asked by At

Why in this piece of code I need call 2 times curl_multi_exec function.

On first loop I'm executing the curl_multi_exec handler to run sub handler. When CURLM_CALL_MULTI_PERFORM is different from $mrc the loop ends.

In second loop, is where we find the results from curl handlers, and the first loop is executed again, Why?

<?php 

    do {
        $mrc = curl_multi_exec($multiHandle, $active);
    } while ($mrc == CURLM_CALL_MULTI_PERFORM);

    while ($active && $mrc == CURLM_OK) {
        if (curl_multi_select($multiHandle, $timeout) != -1) {
            do {
                $mrc = curl_multi_exec($multiHandle, $active);
            } while ($mrc == CURLM_CALL_MULTI_PERFORM);
        }
    }

?>

The code was extracted from PHP-Doc site

1

There are 1 best solutions below

0
On

The answers is here curl_multi_exec().

It's frustrating as the PHP's documentation can be useless in some aspects ...