WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/14/2016 05:29:58 AM (4 years ago)
Author:
rmccue
Message:

HTTP API: Update Requests.

This introduces a minimum value of 1 second for timeouts passed to cURL.

Internally, cURL uses alarm() for interrupts, which accepts a second-resolution timeout. Any values lower than 1 second are instantly failed rather than being rounded upwards. While this makes the experience worse for those using asynchronous DNS lookups, there's no way to detect which DNS resolver is being used from PHP.

See #33055, #8923.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/Requests/Transport/cURL.php

    r37674 r37694  
    177177        $this->process_response($response, $options);
    178178
    179         // Need to remove the $this reference from the curl handle. 
     179        // Need to remove the $this reference from the curl handle.
    180180        // Otherwise Requests_Transport_cURL wont be garbage collected and the curl_close() will never be called.
    181181        curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, null);
     
    350350        }
    351351
    352         if (is_int($options['timeout']) || $this->version < self::CURL_7_16_2) {
    353             curl_setopt($this->handle, CURLOPT_TIMEOUT, ceil($options['timeout']));
     352        // cURL requires a minimum timeout of 1 second when using the system
     353        // DNS resolver, as it uses `alarm()`, which is second resolution only.
     354        // There's no way to detect which DNS resolver is being used from our
     355        // end, so we need to round up regardless of the supplied timeout.
     356        //
     357        // https://github.com/curl/curl/blob/4f45240bc84a9aa648c8f7243be7b79e9f9323a5/lib/hostip.c#L606-L609
     358        $timeout = max($options['timeout'], 1);
     359
     360        if (is_int($timeout) || $this->version < self::CURL_7_16_2) {
     361            curl_setopt($this->handle, CURLOPT_TIMEOUT, ceil($timeout));
    354362        }
    355363        else {
    356             curl_setopt($this->handle, CURLOPT_TIMEOUT_MS, round($options['timeout'] * 1000));
     364            curl_setopt($this->handle, CURLOPT_TIMEOUT_MS, round($timeout * 1000));
    357365        }
    358366
Note: See TracChangeset for help on using the changeset viewer.