简体   繁体   English

为什么在两个循环中使用curl_multi_exec

[英]why curl_multi_exec in two loops

I saw a piece of example code, i wonder why use two do-while loops? 我看到了一段示例代码,我想知道为什么要使用两个do-while循环? 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. 如图所示,第一个循环旨在初始化HTTP客户端。 Normally it only executes once. 通常,它只执行一次。 Then in the second loop the HTTP requests are sent and the responses reaped. 然后,在第二个循环中,发送HTTP请求并获得响应。

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). 如果您希望脚本在等待HTTP请求处理时做一些事情,这不是很方便(您可以将想要做的一些事情放在一个单独的页面中,并将其作为curl资源调用-但是它可以有点混乱)。

See this page for more details and alternate constructs. 有关更多详细信息和替代构造,请参见此页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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