php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77030 curl_multi_select() return value is inconsistent
Submitted: 2018-10-18 09:02 UTC Modified: 2019-05-22 03:23 UTC
From: php-bugs at xpaw dot me Assigned: pierrick (profile)
Status: Assigned Package: cURL related
PHP Version: 7.2.11 OS: All of them
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-10-18 09:02 UTC] php-bugs at xpaw dot me
Description:
------------
Looking at the source code of how curl_multi_select() is implemented, there's various different ways of which values it can return.

And these includes:
- Number of descriptors from curl_multi_wait or curl_multi_fdset depending on the version
- curl version before 7.48 can set numfds to -1 in curl_multi_wait
- native call to select() can return -1 (without any curl error being set, so this return value highly depends on OS it seems)

Basically, many different little differences like that can produce wildly different results, and it's very hard to write a consistent library that uses multi curl.

Here's my library that implements multi curl: https://github.com/xPaw/Crimp.php

And after PHP 7.2.11 released, which uses curl_multi_wait, it looks like the current fix would be:
```
if( $Running ) {
	$Descriptors = curl_multi_select( $Master, 0.1 );

	if( $Descriptors === -1 && curl_multi_errno( $Master ) !== CURLM_OK ) {
		throw new \RuntimeException( 'curl_multi_select failed. error: ' . curl_multi_errno( $Master ) );
	}

	// count number of repeated zero numfds
	if( $Descriptors === 0 ) {
		if( ++$Repeats > 1 ) {
			usleep( 100 );
		}
	} else {
		$Repeats = 0;
	}
}
```

Note that I added a curl_multi_errno check if curl_multi_select returns -1.

I'm not entirely sure what's the elegant way of fixing this would be, but this is clearly a problem that keeps on reoccurring, for example in bug #74334


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-18 10:32 UTC] nikic@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: pierrick
 [2018-10-18 10:32 UTC] nikic@php.net
Assigning to pierrick who landed the fix for bug #76480. We may have to revert this on the stable branches due to the BC break, if it can't be fixed in some other way.
 [2018-10-18 10:37 UTC] php-bugs at xpaw dot me
Please note that this issue aims to create a discussion on the overall design of how curl_multi_select function is implemented, as before using curl_multi_wait internally, there were already cases of inconsistent return values.
 [2019-05-22 03:23 UTC] bishop@php.net
How should we proceed, at this point? The documentation reflects the new return values, and those return values are pretty-well established in released versions (having been out for more than 6 months now). "Wont Fix" seems appropriate...

I did add a note to the documentation[1]

[1]: https://www.php.net/manual/en/function.curl-multi-select.php#123869
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Sep 21 09:01:27 2019 UTC