|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63411 curl_multi_select() returns invalid value
Submitted: 2012-11-01 11:10 UTC Modified: 2013-02-18 00:36 UTC
Avg. Score:4.6 ± 0.8
Reproduced:42 of 42 (100.0%)
Same Version:12 (28.6%)
Same OS:13 (31.0%)
From: marcel at silverstreet dot com Assigned: pierrick
Status: No Feedback Package: cURL related
PHP Version: 5.3.18 OS: CentOS 6.3
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-11-01 11:10 UTC] marcel at silverstreet dot com
curl_multi_select() seems broken in PHP 5.3.18 on CentOS 6.3.

The behavior of the test script below is different than it used to be, returning 
immediately without select with a -1 (failure) return value.

Test script:
$mh = curl_multi_init();
print curl_multi_select($mh, 1.0);

Expected result:
curl_multi_select() should take 1.0 seconds to complete and returns 0

Actual result:
curl_multi_select() returns immediately with return value of -1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-01 18:33 UTC] aa dot vasilenko at gmail dot com
Confirming the same bug. PHP 5.4.8, CentOS 5.8
 [2012-11-02 04:52 UTC]
-Assigned To: +Assigned To: pierrick
 [2012-11-02 04:52 UTC]
This is related to this

There is no handles in the test script, it is expected after the patch.
 [2012-11-03 03:42 UTC]
I'm not sure we really want to wait 1 second for nothing in this specific case.

Furthermore, as mentioned in my commit message, when libcurl returns -1 in 
max_fd after calling curl_multi_fdset, 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().

I would personally keep the current behaviour.
 [2012-11-05 15:21 UTC] aa dot vasilenko at gmail dot com
This bug breaks existing libs, like Buzz , 
that relies on curl_multi_* functions. This is how I came here.
 [2012-11-15 05:39 UTC]
Does it break all the test cases ? Or only like in your case when you have no 
handle ?
 [2012-11-15 05:39 UTC]
-Status: Assigned +Status: Feedback
 [2012-11-15 09:30 UTC] bfanger at gmail dot com
It breaks all my testcases in PHP 5.4.8 (works fine in 5.4.7)

$ git clone git:// testapp/core
$ phpunit --bootstrap testapp/core/phpunit_bootstrap.php 
 [2012-11-15 11:42 UTC] bfanger at gmail dot com
curl_multi_select() returning -1 has been an issue for windows versions of PHP 
for a while:

A workaround for my Curl wrapper class was to rewrite:

if (curl_multi_select(self::$pool, 0.2) === -1) {
   throw new \Exception('Failed to detect changes in the cURL multi handle');


if (curl_multi_select(self::$pool, 0.2) === -1) {
   usleep(100000); // wait 0.1 second

When are you going to introduce the new curl_multi_wait function to php?
 [2012-11-15 13:54 UTC]
As mentioned in bug #61141, curl_multi_select() returning -1 is an expected behaviour and you should not throw an exception which prevent your call to 
be done.

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 
our own particular conditions to find a suitable value.

The workaround you made is not really a workaround, but is exactly what libcurl recommend you to do in this case :)
 [2013-02-18 00:36 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 [2013-03-13 12:14 UTC]
What's the point of a select() call that doesn't block?
The whole point of curl_multi_select is to block until either there's some 
activity on the socket, or the timeout is reached.
The curl_multi_select() call now returns immediately (with -1), without waiting 
for the timeout, in all our use cases too, making it useless.
Why was the behaviour changed in the first place? Is it possible to revert?
 [2013-06-05 19:40 UTC] yang dot phpbugs at mailnull dot com
I'm also finding this to be breaking various libraries including JAXL.
 [2015-05-18 09:53 UTC] public-mail at alekciy dot ru
I confirm to https (http OK). curl_multi_select() always and immediately return -1. Env:

test:~$ cat /etc/os-release 
VERSION="14.04.2 LTS, Trusty Tahr"
PRETTY_NAME="Ubuntu 14.04.2 LTS"

test:~$ php -v
PHP 5.5.9-1ubuntu4.9 (cli) (built: Apr 17 2015 11:44:57) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
test:~$ curl -V
curl 7.35.0 (x86_64-pc-linux-gnu) libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smtp smtps telnet tftp 
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP
 [2016-01-28 14:41 UTC] nemanjan00 at gmail dot com
I also have this problem on arch linux. 

$ php -v
PHP 7.0.2 (cli) (built: Jan  6 2016 11:50:59) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

curl_multi_select() always return -1
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC