PHP :: Bug #76480 :: Use curl_multi_wait() so that timeouts are respected
php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76480 Use curl_multi_wait() so that timeouts are respected
Submitted: 2018-06-15 07:03 UTC Modified: 2018-08-14 02:04 UTC
Votes:4
Avg. Score:4.5 ± 0.9
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:2 (50.0%)
From: tstarling@php.net Assigned: pierrick (profile)
Status: Assigned Package: cURL related
PHP Version: 7.3Git-2018-06-15 (Git) OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tstarling@php.net
New email:
PHP Version: OS:

 

 [2018-06-15 07:03 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-14 02:04 UTC] pierrick@php.net
-Assigned To: +Assigned To: pierrick
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Aug 20 22:01:26 2018 UTC