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. git-svn-id: https://develop.svn.wordpress.org/trunk@37694 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
af48ea92de
commit
87b095dae9
@ -349,11 +349,19 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_int($options['timeout']) || $this->version < self::CURL_7_16_2) {
|
// cURL requires a minimum timeout of 1 second when using the system
|
||||||
curl_setopt($this->handle, CURLOPT_TIMEOUT, ceil($options['timeout']));
|
// DNS resolver, as it uses `alarm()`, which is second resolution only.
|
||||||
|
// There's no way to detect which DNS resolver is being used from our
|
||||||
|
// end, so we need to round up regardless of the supplied timeout.
|
||||||
|
//
|
||||||
|
// https://github.com/curl/curl/blob/4f45240bc84a9aa648c8f7243be7b79e9f9323a5/lib/hostip.c#L606-L609
|
||||||
|
$timeout = max($options['timeout'], 1);
|
||||||
|
|
||||||
|
if (is_int($timeout) || $this->version < self::CURL_7_16_2) {
|
||||||
|
curl_setopt($this->handle, CURLOPT_TIMEOUT, ceil($timeout));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
curl_setopt($this->handle, CURLOPT_TIMEOUT_MS, round($options['timeout'] * 1000));
|
curl_setopt($this->handle, CURLOPT_TIMEOUT_MS, round($timeout * 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_int($options['connect_timeout']) || $this->version < self::CURL_7_16_2) {
|
if (is_int($options['connect_timeout']) || $this->version < self::CURL_7_16_2) {
|
||||||
|
@ -304,6 +304,8 @@ class Requests {
|
|||||||
* options:
|
* options:
|
||||||
*
|
*
|
||||||
* - `timeout`: How long should we wait for a response?
|
* - `timeout`: How long should we wait for a response?
|
||||||
|
* Note: for cURL, a minimum of 1 second applies, as DNS resolution
|
||||||
|
* operates at second-resolution only.
|
||||||
* (float, seconds with a millisecond precision, default: 10, example: 0.01)
|
* (float, seconds with a millisecond precision, default: 10, example: 0.01)
|
||||||
* - `connect_timeout`: How long should we wait while trying to connect?
|
* - `connect_timeout`: How long should we wait while trying to connect?
|
||||||
* (float, seconds with a millisecond precision, default: 10, example: 0.01)
|
* (float, seconds with a millisecond precision, default: 10, example: 0.01)
|
||||||
|
Loading…
Reference in New Issue
Block a user