Doc #61141 [Nab]: curl_multi_select returns -1

From: Date: Sat, 22 Sep 2012 13:44:50 +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-8885@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: 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); } Previous Comments: ------------------------------------------------------------------------ [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). ------------------------------------------------------------------------ [2012-09-22 09:35:07] amoo_miki at yahoo dot com PHP 5.3.17 and 5.4.7 too suffer from this bug. ------------------------------------------------------------------------ [2012-06-06 20:57:57] ihate at spam dot com Always returns -1 on Windows 7 64bit. Tried on 5.4 and 5.4.3. It worked a couple of months ago, perhaps some Win7 update changed something. ------------------------------------------------------------------------ [2012-05-30 02:48:04] laruence@php.net Pierrick, could you please look at this? :) ------------------------------------------------------------------------ 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

« previous php.doc.bugs (#8885) next »