When I run the below code it seems to me curl_multi_select and curl_multi_info_read are contradicting each other. As I understand it curl_multi_select is supposed to be blocking until curl_multi_exec has a response but I haven’t seen that actually happen.
$url = "http://google.com";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
$mc = curl_multi_init();
curl_multi_add_handle($mc, $ch);
do {
$exec = curl_multi_exec($mc, $running);
} while ($exec == CURLM_CALL_MULTI_PERFORM);
$ready=curl_multi_select($mc, 100);
var_dump($ready);
$info = curl_multi_info_read($mc,$msgs);
var_dump($info);
this returns
int 1
boolean false
which seems to contradict itself. How can it be ready and not have any messages?
The php version I’m using is 5.3.9
Basically
curl_multi_selectblocks until there is something to read or send withcurl_multi_exec. If you loop aroundcurl_multi_execwithout usingcurl_multi_selectthis will eat up 100% of a CPU core.So
curl_multi_info_readis used to check if any transfer has ended (correctly or with an error).Code using the multi handle should follow the following pattern:
See also: Doing curl_multi_exec the right way.