php.net |  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: 2018-09-18 01:45 UTC
Votes:47
Avg. Score:4.6 ± 0.8
Reproduced:46 of 46 (100.0%)
Same Version:12 (26.1%)
Same OS:13 (28.3%)
From: marcel at silverstreet dot com Assigned: pierrick (profile)
Status: Closed Package: cURL related
PHP Version: 5.3.18 OS: CentOS 6.3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: marcel at silverstreet dot com
New email:
PHP Version: OS:

 

 [2012-11-01 11:10 UTC] marcel at silverstreet dot com
Description:
------------
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);
curl_multi_close($mh);


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


Patches

Pull Requests

History

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] reeze@php.net
-Assigned To: +Assigned To: pierrick
 [2012-11-02 04:52 UTC] reeze@php.net
This is related to this
see:
https://github.com/php/php-src/commit/2e8ab65270e7d1ebe1ef0dfe13836c29d72c7010
http://curl.haxx.se/libcurl/c/curl_multi_fdset.html

There is no handles in the test script, it is expected after the patch.
 [2012-11-03 03:42 UTC] pierrick@php.net
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 https://github.com/kriswallsmith/Buzz , 
that relies on curl_multi_* functions. This is how I came here.
 [2012-11-15 05:39 UTC] pierrick@php.net
Does it break all the test cases ? Or only like in your case when you have no 
handle ?
 [2012-11-15 05:39 UTC] pierrick@php.net
-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://github.com/sledgehammer/core.git testapp/core
$ phpunit --bootstrap testapp/core/phpunit_bootstrap.php 
testapp/core/tests/CurlTest.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:
https://bugs.php.net/bug.php?id=61141

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');
}

To:

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


PS:
When are you going to introduce the new curl_multi_wait function to php?
 [2012-11-15 13:54 UTC] pierrick@php.net
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] quipo@php.net
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 
NAME="Ubuntu"
VERSION="14.04.2 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.2 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"

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
 [2018-08-03 15:06 UTC] cmb@php.net
-Status: No Feedback +Status: Re-Opened
 [2018-08-03 15:06 UTC] cmb@php.net
Re-opening, since feedback has been given long ago.

See also bug #76480.
 [2018-09-18 01:45 UTC] pierrick@php.net
-Status: Re-Opened +Status: Closed
 [2018-09-18 01:45 UTC] pierrick@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC