understanding php curl_multi_exec

前端 未结 1 835
臣服心动
臣服心动 2020-12-01 05:14

I\'m trying to understand curl_multi_exec. I\'ve copied a piece of the manual example here. So I\'m wondering, how does it work? The first loop sends the http request I gues

相关标签:
1条回答
  • 2020-12-01 06:10

    You can explore two article that describes this example.

    PHP and curl_multi_exec

    First, here's the high level. There are two outer loops. The first one is responsible for clearing out the curl buffer right now. The second one is responsible for waiting for more information, and then getting that information. This is an example of what is called blocking I/O. We block execution of the rest of the program until the network I/O is done. While this isn't the most preferable way in general to handle network I/O, it's really our only choice in single-threaded, synchronous PHP.

    Doing curl_multi_exec the right way

    First the $mrc variable and from the manual we learn that the response is a cURL code defined in the cURL Predefined Constants. In essence it is a regular response and as with any other PHP function curl_multi_exec is no different and only returns a response once it is finished. Which means there should be only ONE response. In a perfect world this single response is 0 (zero) or equal to the predefined constant CURLM_OK.

    0 讨论(0)
提交回复
热议问题