Extending WordPress HTTP Request Timeout Lengths

Posted Feb 21, 2014

The WordPress HTTP API allows developers to easily make HTTP requests across different server configurations, but by default the request times out after 5 seconds. This keeps page load times down on your site if an external request is taking too long, but in some situations you run into errors like "name lookup timed out". Here's how both average users and developers can fix WordPress HTTP request timeouts.

How to Fix "name lookup timed out"

If you're just a normal WordPress users and seeing this error, there's an easy fix. We've written a free plugin that increases the default timeout length from 5 seconds to 30 seconds. This should decrease the chance of running into timeout errors, but you'll still have errors if the URL being requested is having connection issues.

Download our Extend HTTP Request Timeout WordPress Plugin and upload it to your site. Once activated from the plugins panel, you should experience fewer timeouts.

Developer's Guide to HTTP Timeout Errors

If you're a developer you may have stumbled across the "httprequesttimeout" filter. This can be applied site-wide, but it might be wiser to only modify your requests. If you haven't had any timeout issues there's no need to increase the default, but since you're reading this I'll assume you have. If your plugin is making requests that are frequently timing out, you can override the default timeout when using one of the WordPress HTTP API functions like wpremoteget() or wpremotepost(). All you need to do is pass an array of arguments as the second parameter. Here's an example:

wp_remote_get( 'http://example.com/request', array( 'timeout' => 30 ) );

Keep in mind that setting longer timeouts means that users' sites might take longer to load when the URL being requested is slow or having connectivity issues, so look for the right balance between making sure requests have enough time and making sure you aren't waiting 30 seconds for a request that will never load.

Other Resources

Be sure to check out the full documentation on the WordPress HTTP API.

Developers trying to debug issues with their HTTP requests should check out the Core Control plugin. You can enable a log for requests made with the HTTP API which will come in handy for diagnosing intermittent timeouts.