why curl_multi_exec in two loops

£可爱£侵袭症+ 提交于 2019-12-12 04:56:17

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/28735721/why-curl-multi-exec-in-two-loops

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!