简体   繁体   English

curl_multi_exec()是阻塞调用吗?

[英]Is curl_multi_exec() a blocking call?

如果PHP中的curl_multi_exec()调用是阻塞或非阻塞调用,那只是好奇。

Shot answer : curl_multi_exec() is non-blocking 镜头回答curl_multi_exec()非阻塞的


Longer answer : curl_multi_exec() is non-blocking , but blocking can be made with the combination of curl_multi_select , which blocks until there is activity on any of the curl_multi connections. 更长的答案curl_multi_exec()非阻塞的 ,但是可以使用curl_multi_select的组合进行curl_multi_selectcurl_multi_select会阻塞,直到任何curl_multi连接上存在活动。

Edit: Currently I am working on a crawler, this is outline of a piece of code I used. 编辑:目前我正在使用爬虫,这是我使用的一段代码的概述。

do {
    $mrc = curl_multi_exec($mh, $active);
    if($to_db_queue->count()>0){
       while($to_db_queue->count()>0)
          //dequeue from queue and insert into database
    }
    else  
      curl_multi_select($mh); //block till state change
} while ($active > 0);

This code will make a curl_multi_exec and then will continue its database work queued in $to_db_queue , else if nothing in queue curl_multi_select will be called to block the loop until a state change occur in curl_multi connections. 此代码将生成curl_multi_exec ,然后将继续在$to_db_queue排队的数据库工作,否则如果队列curl_multi_select没有任何curl_multi_select将被调用以阻止循环,直到curl_multi连接中发生状态更改。

More example: 更多例子:
non-blocking 非阻塞
blocking 闭塞

Hope this will help you understand the concept. 希望这能帮助您理解这个概念。

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

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