简体   繁体   中英

php curl_multi_exec current executing curl name

Is there a way to find out which curl is being executed by the curl_multi_exec in this function...which is more or less provided on php.net ?

<?php
...
$mh = curl_multi_init();

//add the five handles
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);
curl_multi_add_handle($mh,$ch3);
curl_multi_add_handle($mh,$ch4);
curl_multi_add_handle($mh,$ch5);
do {
    $mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active && $mrc == CURLM_OK) {
    if (curl_multi_select($mh) == -1) {
        usleep(1);
    }
    do {
        $mrc = curl_multi_exec($mh, $active);
    } while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
...
?>

All requests are started at the first curl_multi_exec and then will run asyncronously.

Subsequent calls to curl_multi_exec in the code posted serve the purpose to periodically check if there are requests still in progress (by reading the value returned by reference into $active ).

The value returned into $mrc is also checked, normally it is CURLM_CALL_MULTI_PERFORM (multi curl still running), or CURLM_OK (multi curl is done - $active should be FALSE ). See http://php.net/manual/en/curl.constants.php and search for text beginning with CURLM_ to see all the constants related to curl multi.

Said that your question has no answer. All requests run in parallel then they come to an end as they are fulfilled or an error occurrs. When all requests are done the values returned by curl_multi_exec let the loop exit and allow the script execution to proceed.

Note however that you may call curl_multi_info_read to gather information about the current transfers; at the time of writing you may know which requests are done (and by exclusion which are still running);

from the manual:

Ask the multi handle if there are any messages or information from the individual transfers. Messages may include information such as an error code from the transfer or just the fact that a transfer is completed.

Repeated calls to this function will return a new result each time, until a FALSE is returned as a signal that there is no more to get at this point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM