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
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 functioncurl_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 constantCURLM_OK
.