Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/Transport/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,24 @@ private function setup_handle($url, $headers, $data, $options) {

// cURL requires a minimum timeout of 1 second when using the system
// 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);
$using_asynch_dns = false;
if (defined('CURL_VERSION_ASYNCHDNS')) {
$curl_version = curl_version();
// phpcs:ignore PHPCompatibility.Constants.NewConstants.curl_version_asynchdnsFound
if (CURL_VERSION_ASYNCHDNS & $curl_version['features']) {
$using_asynch_dns = true;
}
}

if ($using_asynch_dns) {
// It should be safe to use any timeout, even if less than 1 second.
$timeout = $options['timeout'];
} else {
// If the timeout is less than 1 second, we need to round up.
$timeout = max($options['timeout'], 1);
}

if (is_int($timeout) || $this->version < self::CURL_7_16_2) {
curl_setopt($this->handle, CURLOPT_TIMEOUT, ceil($timeout));
Expand Down