A Bell System switchboard where overseas calls are handled. Not all of the services shown are available during wartime conditions

WordPress cURL Error 28 and Your DNS Resolver

Hey! This article is for advanced users managing their own server. If you have shared hosting or another managed service, talk to your provider to fix this. That’s what you pay them for!

I recently had an issue where a Digital Ocean droplet hosting a WordPress site was experiencing cURL error 28. This error is related to timeouts when performing a cURL request. I specifically noticed it when using Mailgun to send email from my website. Its API options utilize cURL. My Gravity Form notifications, and even the Mailgun test, were timing out.

Don’t Tinker With WordPress Timeout Values

For the purposes of testing, you can certainly change WordPress’s cURL timeout value, which is 5 seconds by default. You might increase it to see if your request eventually posts successfully.

But 5 seconds should be way more than enough for production. Various plugins may be making cURL requests. If those requests are happening on the front end of your website, users will now be waiting for those to complete, even if it takes a while. A slow website is a bad website.

Diagnose the Problem

Mailgun was simply telling me there was a timeout error. Not super informative. To the command line! SSH into your server and try a cURL request. Get some timing diagnostics while you’re at it. Here’s a great article on doing that, but what you need to know is:

$ curl -s -w "%{time_total}\n" -o /dev/null http://www.google.com/

That should spit out a time, and it should be quick. If the time is under 1 second, that’s a good sign. If you run it a few times and it always comes in under 5 seconds (WordPress’s default timeout value), your problem is likely rooted in WordPress and not your server. Start the regular WordPress debugging process of deactivating all plugins and switching to a default theme.

If, however, this takes longer than 5 seconds, the problem is probably your server, not WordPress. The next step is to check the DNS resolver. Replace the URL you used in the above command with the IP address for the same URL.

$ curl -s -w "%{time_total}\n" -o /dev/null

If your response is suddenly very quick, the problem is likely your DNS resolver.

Changing Your DNS Resolver

DigitalOcean has a great article on how to get in and permanently change your DNS resolver on a couple of different setups, including Ubuntu/Debian and CentOS/RHEL. I won’t repeat that all here, as I’ve written this mostly for helping folks debug. But do keep in mind that you’ll want to `sudo` for most of that.

Still Having Issues?

Make sure your PHP and cURL libraries are up-to-date. And if you still have issues, I wish you the best of luck! You’re on your own.

Tom Haverford abandoning Mark and April while canvassing


One response to “WordPress cURL Error 28 and Your DNS Resolver”

  1. Very nice information in this article.

Leave a Reply

Your email address will not be published. Required fields are marked *