curl_multi_exec()是阻塞调用吗? [英] Is curl_multi_exec() a blocking call?

查看:90
本文介绍了curl_multi_exec()是阻塞调用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好奇的是,PHP中的curl_multi_exec()调用是阻塞调用还是非阻塞调用.

Was just curious if the curl_multi_exec() call in PHP is blocking or non-blocking call.

推荐答案

快速解答:curl_multi_exec()无阻塞

更长的答案:curl_multi_exec()非阻塞,但是可以通过curl_multi_select 的组合来进行阻塞,这会阻塞直到任何curl_multi连接上都处于活动状态.

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.

修改: 目前,我正在研究搜寻器,这是我使用的一段代码的概述.

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

此代码将生成一个curl_multi_exec,然后继续其在$to_db_queue中排队的数据库工作,否则,如果队列curl_multi_select中的任何内容都没有被调用以阻塞循环,直到curl_multi连接中的状态发生改变.

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.

更多示例:
无阻塞
阻止

More example:
non-blocking
blocking

希望这会帮助您理解概念.

Hope this will help you understand the concept.

这篇关于curl_multi_exec()是阻塞调用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆