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.
/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, email@example.com 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