简体   繁体   中英

why curl_multi_exec in two loops

I saw a piece of example code, i wonder why use two do-while loops? what are difference between the two loops? wait reply online, Thank You~~

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);
    }
}

As presented, the first loop is intended to initialize the HTTP clients. Normally it only executes once. Then in the second loop the HTTP requests are sent and the responses reaped.

This isn't very handy if you want your script to do something while its waiting for the HTTP requests to be handled (you could put some of the stuff you want to do in a separate page and call that as a curl resource - but its a bit messy).

See this page for more details and alternate constructs.

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