wp_http remote request not respecting timeout

I suspect this is the cause in the Requests library that powers WP_HTTP:

  • Transfer & connect timeouts, in seconds & milliseconds

cURL is unable to handle timeouts under a second in DNS lookups, so we round
those up to ensure 1-999ms isn’t counted as an instant failure.

The code looks to be here:

https://github.com/WordPress/Requests/blob/90db63ab54449c071fc2192a4fc3487cafbf67d0/src/Transport/Curl.php#L448-L460

        if (is_int($timeout) || $this->version < self::CURL_7_16_2) {
            curl_setopt($this->handle, CURLOPT_TIMEOUT, ceil($timeout));
        } else {
            // phpcs:ignore PHPCompatibility.Constants.NewConstants.curlopt_timeout_msFound
            curl_setopt($this->handle, CURLOPT_TIMEOUT_MS, round($timeout * 1000));
        }

If your goal is to test that a response time is within a certain limit by using the timeout so it fails when it takes too long, as clever as it sounds there are other things that interfere. Instead timing the request at the API server side, and at the client side, then using the time taken to implement your own timeout test would be more reliable ( and give you the opportunity to add more logic, e.g. a warning threshold ).

https://github.com/WordPress/Requests/issues/58

It’s also possible your server is using an old version of curl that does not support microsecond based timeouts