diff --git a/src/Transport/Curl.php b/src/Transport/Curl.php index 18de09d2a..521d42774 100644 --- a/src/Transport/Curl.php +++ b/src/Transport/Curl.php @@ -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));