Bug #76480 [NEW]: Use curl_multi_wait() so that timeouts are respected
| From: | tstarling@php.net | Date: | Fri, 15 Jun 2018 07:03:11 +0000 |
| Subject: | Bug #76480 [NEW]: Use curl_multi_wait() so that timeouts are respected | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-215732@lists.php.net to get a copy of this message | ||
From: tstarling
Operating system: Linux
PHP version: 7.3Git-2018-06-15 (Git)
Package: cURL related
Bug Type: Bug
Bug description:Use curl_multi_wait() so that timeouts are respected
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 bug report at https://bugs.php.net/bug.php?id=76480&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76480&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76480&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76480&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76480&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76480&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76480&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76480&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76480&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76480&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76480&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76480&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76480&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76480&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76480&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76480&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76480&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76480&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76480&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76480&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76480&r=mysqlcfg