I've been running into trouble with all my localhost install of Wordpress reporting cURL error 28 (timeout) since (I believe!)I've switched my PHP version from 7.0 to 7.2 with brew on my local Mac OS machine. Viewing any of my local site’s admin areas or using the WP CLI the WP update checks and other cURL calls result in failing cURL requests:
Warning: An unexpected error occurred. Something may be wrong with WordPress or this server’s configuration. If you continue to have problems, please try the support forums. (WordPress could not establish a secure connection to WordPress. Please contact your server administrator.) in /Users/…/wp-includes/update.php on line xxx
(xxx line varies on which install, local https site or not, etc, but always boils down to a line catching a curl error)
From what I can tell PHP is using the brew installed cURL and cURL works both in CLI and in PHP, e.g. running this explicitly in a theme functions.php works and returns the expected result (a JSON of updates):
$ch = curl_init(".7/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
var_dump("exec", curl_exec($ch));
var_dump("error", curl_error($ch));
curl_close($ch);
Equally, just getting a cURL request on the terminal works as well:
curl -v .7/
Both return the same JSON.
I've tried to edit my WP’s /wp-includes/
various http, request and cURL related classes to debug what is going on. Since the functios.php’s cURL works, but WP’s internal do not, I assume my PHP cURL is working per se.
In /wp-includes/Requests/Transports/cURL.php
I've tried to comment out as many curl_setopt
calls as possible to approximate the same minimal cURL call that works in my functions.php but with no luck — also I don't know of a way to see the exact cURL settings the request goes out with. curl_getinfo
reveals mostly empty or defaulted values, like what I'd expect with a request that never succeeded.
Other things I've tried and checked:
I'm absolutely baffled about what is going on here and why WP’s cURL requests are failing and essentially rendering my entire development environment useless.
Any help or suggestions to get to the bottom of this is very, very much appreciated.
Edit: FYI, same issue on stackoverflow as well:
I've been running into trouble with all my localhost install of Wordpress reporting cURL error 28 (timeout) since (I believe!)I've switched my PHP version from 7.0 to 7.2 with brew on my local Mac OS machine. Viewing any of my local site’s admin areas or using the WP CLI the WP update checks and other cURL calls result in failing cURL requests:
Warning: An unexpected error occurred. Something may be wrong with WordPress or this server’s configuration. If you continue to have problems, please try the support forums. (WordPress could not establish a secure connection to WordPress. Please contact your server administrator.) in /Users/…/wp-includes/update.php on line xxx
(xxx line varies on which install, local https site or not, etc, but always boils down to a line catching a curl error)
From what I can tell PHP is using the brew installed cURL and cURL works both in CLI and in PHP, e.g. running this explicitly in a theme functions.php works and returns the expected result (a JSON of updates):
$ch = curl_init("http://api.wordpress/core/version-check/1.7/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
var_dump("exec", curl_exec($ch));
var_dump("error", curl_error($ch));
curl_close($ch);
Equally, just getting a cURL request on the terminal works as well:
curl -v http://api.wordpress/core/version-check/1.7/
Both return the same JSON.
I've tried to edit my WP’s /wp-includes/
various http, request and cURL related classes to debug what is going on. Since the functios.php’s cURL works, but WP’s internal do not, I assume my PHP cURL is working per se.
In /wp-includes/Requests/Transports/cURL.php
I've tried to comment out as many curl_setopt
calls as possible to approximate the same minimal cURL call that works in my functions.php but with no luck — also I don't know of a way to see the exact cURL settings the request goes out with. curl_getinfo
reveals mostly empty or defaulted values, like what I'd expect with a request that never succeeded.
Other things I've tried and checked:
I'm absolutely baffled about what is going on here and why WP’s cURL requests are failing and essentially rendering my entire development environment useless.
Any help or suggestions to get to the bottom of this is very, very much appreciated.
Edit: FYI, same issue on stackoverflow as well: https://stackoverflow/questions/54906545/how-to-set-or-circumvent-curlopt-connecttimeout-in-php-globally
In my testing this is a problem with DNS resolving. In my case it's because the DNS filter/cache I run on my local network wasn't responding to requests. After restarting the service on the DNS server my requests got through quickly & easily. I would suggest checking any local DNS servers on your network.
OP also resolved the problem by specifically changing DNS settings to Google's DNS provider, but I saw elsewhere that for some problem the problem was Google's DNS, so switching away from Google fixed the problem.
If it's a CURL_CONNECTTIMEOUT problem, then you I think you can do this:
function filter_request_timeout($timeout) {
return 100; // desired time in seconds
}
add_filter('http_request_timeout', 'filter_request_timeout' );
Both CURLOPT_CONNECTTIMEOUT
and CURLOPT_TIMEOUT
use the same value when the timeout is set: https://github/WordPress/WordPress/blob/master/wp-includes/class-wp-http-curl.php#L127
However, if this just happened since installing PHP 7.2 maybe there's another reason. Did you update the cURL extension as well? I'm having the same issue on PHP 7.3 via Homebrew, so I'm going to see what I can do without resorting to adding a filter to the dev version of all my sites.
Update: the http_request_timeout
filter is for the default timeout. If the timeout has been set between getting the default and sending the request, it needs to happen in the http_request_args
filter:
function johnbeales_filter_request_args( $args, $url ) {
if(strpos($url, 'wordpress') !== false ) {
$args['timeout'] = 100; // Timeout in seconds
}
return $args;
}
add_filter('http_request_args', 'johnbeales_filter_request_args', 10, 2);
Since we're having trouble connecting to wordpress, I only adjusted the timeout on requests to wordpress.
WP_HTTP_BLOCK_EXTERNAL
set, do you? Since it's an issue with resolving, could you try curling the IP for api.wordpress instead of the domain name. Also, try settingCURLOPT_CONNECTTIMEOUT
to 30 seconds or longer. – MikeNGarrett Commented Feb 26, 2019 at 15:37WP_HTTP_BLOCK_EXTERNAL
set and am also trying this form different local installations. Curl’ing the IP I get a 302 because it seems to fetch from wordpress not api.wordpress, but I think this can be expected. Increasing the timeout, via filter, constants or directly in WP core classes does not have any other effect except it taking longer to timeout; it’s not an issue with an actual timeout, I reckon, just that the timeout is the final trigger for aborting the cURL that is set to fail from the beginning. – kontur Commented Feb 27, 2019 at 7:09CURLOPT_CONNECTTIMEOUT
, actually! I've looked at theCURLOPT_TIMEOUT
option all the time, changing it’s values, but bumpingCURLOPT_CONNECTTIMEOUT
actually resolves the issue, partially. The problem is a) I don't know what changed in my PHP upgrade that the behavior in this regard is different now, and b) I don't know how to set this aside from thehttp_api_curl
— for example my WP CLI calls still fail, because they use the 10s default defined in/wp-includes/class-request.php
. – kontur Commented Feb 27, 2019 at 13:16