Doc #61141 [Nab]: curl_multi_select returns -1
| From: | pierrick@php.net | Date: | Sat, 22 Sep 2012 14:13:39 +0000 |
| Subject: | Doc #61141 [Nab]: curl_multi_select returns -1 | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-8890@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61141&edit=1
ID: 61141
Updated by: pierrick@php.net
Reported by: amoo_miki at yahoo dot com
Summary: curl_multi_select returns -1
Status: Not a bug
Type: Documentation Problem
Package: cURL related
Operating System: Windows 7 x64
PHP Version: 5.3.10
Assigned To: pierrick
Block user comment: N
Private report: N
New Comment:
The change that introduced your problem is somewhere in libcurl. You could submit
a bug to libcurl, but I'm pretty sure they will come with the same answer as I
did since it's documented.
I know that the code will work even if you never call curl_multi_select but I
would recommend you to use it anyway to make sure you'll not consume all your cpu
resources and I would follow the libcurl recommandation to sleep some time before
executing the curl_multi_exec
Previous Comments:
------------------------------------------------------------------------
[2012-09-22 14:03:06] amoo_miki at yahoo dot com
i reread your comment about
The libcurl documentations says "When max_fd returns
with -1, you need to wait a while and then proceed and call curl_multi_perform
anyway"...
... the keyword being "anyway".
------------------------------------------------------------------------
[2012-09-22 13:56:43] amoo_miki at yahoo dot com
Gotcha. The code change you propose works, but not sure why it doesn't make sense to me.
while ($active && $mrc == CURLM_OK) {
do { $mrc = curl_multi_exec($mh, $active); }
while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
The above piece works too, without needing the timeout, but that mean skipping the curl_multi_select
altogether, practically what you found is that we can do without checking curl_multi_select which
doesn't solve the problem with curl_multi_select.
See where i am going?
Also, thanks for looking into this. curl_multi_select is a very useful function and it would be
crazy not to use it.
------------------------------------------------------------------------
[2012-09-22 13:49:52] amoo_miki at yahoo dot com
I should also add that, the sample code, without the sleep works perfectly fine on non-windows
setups. I verified it using 5.3.13 which uses cURL 7.24.0 on OSX.
------------------------------------------------------------------------
[2012-09-22 13:44:50] pierrick@php.net
No, sorry if I was unclear. The libcurl documentations says "When max_fd returns
with -1, you need to wait a while and then proceed and call curl_multi_perform
anyway".
If you translate this in PHP (That was where I was unclear) : "When
curl_multi_select returns with -1, you need to wait a while and then proceed and
call curl_multi_exec anyway"
Then, you should have something like this :
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) == -1) usleep(100);
do { $mrc = curl_multi_exec($mh, $active); }
while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
------------------------------------------------------------------------
[2012-09-22 13:38:44] amoo_miki at yahoo dot com
I modified the script and put a sleep(10) and it still doesn't work. Here is the script i used;
was this what you meant?
<?php
$ch1 = curl_init();
$ch2 = curl_init();
curl_setopt($ch1, CURLOPT_URL, "http://windows.php.net/downloads/releases/md5sum.txt");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_URL, "http://windows.php.net/downloads/releases/sha1sum.txt");
curl_setopt($ch2, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
$mh = curl_multi_init();
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);
$active = null;
do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1)
do { $mrc = curl_multi_exec($mh, $active); }
while ($mrc == CURLM_CALL_MULTI_PERFORM);
else {
echo "* Sleeping for 10 secs\n";
sleep(10);
}
}
echo strlen(curl_multi_getcontent($ch1))."-".strlen(curl_multi_getcontent($ch2));
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);
?>
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=61141
--
Edit this bug report at https://bugs.php.net/bug.php?id=61141&edit=1