Bug #76480 [Com]: Use curl_multi_wait() so that timeouts are respected
| From: | mimipim at abv dot bg | Date: | Fri, 12 Oct 2018 15:04:18 +0000 |
| Subject: | Bug #76480 [Com]: Use curl_multi_wait() so that timeouts are respected | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217537@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76480&edit=1
ID: 76480
Comment by: mimipim at abv dot bg
Reported by: tstarling@php.net
Summary: Use curl_multi_wait() so that timeouts are respected
Status: Closed
Type: Bug
Package: cURL related
Operating System: Linux
PHP Version: 7.3Git-2018-06-15 (Git)
Assigned To: pierrick
Block user comment: N
Private report: N
New Comment:
Please push this fix for PHP 5.6 too!
Previous Comments:
------------------------------------------------------------------------
[2018-09-18 01:45:16] 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.
------------------------------------------------------------------------
[2018-08-03 15:06:36] cmb@php.net
Related To: Bug #63411
------------------------------------------------------------------------
[2018-06-15 07:03:03] tstarling@php.net
Description:
------------
Calling curl_multi_select() causes the application to wait for a fixed, user-supplied timeout value.
If the remaining configured timeout (according to CURLOPT_TIMEOUT etc.) is shorter than the select
timeout, the configured timeout is only checked after the select timeout finishes.
This means that the user is forced to choose a short select timeout, so that configured timeouts are
checked sufficiently often. The user has no easy way to derive the correct maximum select timeout.
To fix this, libcurl 7.28 introduced curl_multi_wait(), which is a select() wrapper that respects
configured timeouts. I propose using this function in PHP instead of select(). Code review confirms
that this has not yet been done as of today's git master.
Incidentally, HHVM has already made this change.
Test script:
---------------
<?php
$mh = curl_multi_init();
// Use address blackholed with: iptables -A INPUT -d 127.0.0.44 -j DROP
$c = curl_init('http://127.0.0.44/');
curl_setopt($c, CURLOPT_TIMEOUT, 1);
curl_multi_add_handle($mh, $c);
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
$t = microtime(true);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh, 10) != -1) {
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
print round(microtime(true) - $t) . "\n";
Expected result:
----------------
1
Actual result:
--------------
10
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76480&edit=1