Doc #61141 [Com]: curl_multi_select returns -1
| From: | amoo_miki at yahoo dot com | Date: | Sat, 22 Sep 2012 14:03:06 +0000 |
| Subject: | Doc #61141 [Com]: curl_multi_select returns -1 | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-8889@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
Comment by: amoo_miki at yahoo dot com
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:
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".
Previous Comments:
------------------------------------------------------------------------
[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);
?>
------------------------------------------------------------------------
[2012-09-22 13:22:02] pierrick@php.net
I tried this on my windows setup with the same version of PHP but two different
versions of libcurl (7.19 and 7.24) and this difference is due to the libcurl
version used to compile ext/curl but this is in fact not a bug.
Internally php curl_multi_select uses libcurl curl_multi_fdset function to set
all the fd_set and the maxfd value. The libcurl curl_multi_fdset documentation
says :
When libcurl returns -1 in max_fd, it is because libcurl currently does
something that isn't possible for your application to monitor with a socket and
unfortunately you can then not know exactly when the current action is completed
using select(). When max_fd returns with -1, you need to wait a while and then
proceed and call curl_multi_perform anyway. How long to wait? I would suggest
100 milliseconds at least, but you may want to test it out in your own
particular conditions to find a suitable value.
If you modify the script to wait some time if the curl_multi_select return -1
and then do the curl_multi_exec it should work (it worked on my setup with both
curl versions).
------------------------------------------------------------------------
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