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.org 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.org. 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.org/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.org/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:
- Installed Health Check plugin to confirm: Yes, REST API fails, Connection to Wordpress.org fails, Loopback request fails
- Various combinations of: Disabled plugins & themes, no plugins, fresh WP install
- phpinfo() tells me cURL is enabled (v7.64.0)
- I reinstalled curl, openssh, php@7.2 via brew several times
- Restarted computer, restarted apache server
- Posted on wp.org
- Checked php error log, checked WP debug.log, set error_reporting to (E_ALL): Nothing suspicious in regards to cURL calls shows up
- Firewall is disabled (also the other cURL calls work, so…)
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.com/questions/54906545/how-to-set-or-circumvent-curlopt-connecttimeout-in-php-globally
WP_HTTP_BLOCK_EXTERNAL
set, do you? Since it's an issue with resolving, could you try curling the IP for api.wordpress.org instead of the domain name. Also, try settingCURLOPT_CONNECTTIMEOUT
to 30 seconds or longer.WP_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.org not api.wordpress.org, 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.CURLOPT_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
.