Encountering the “cURL error 28: Connection timed out after X seconds” message can be quite frustrating for WordPress users and site admins. But thankfully, this common error is fixable through some targeted debugging and optimization techniques.
In this comprehensive guide, we’ll cover what causes cURL timeout errors, 12 potential fixes to resolve them, and best practices to avoid these issues in the future. Read on to learn how to banish connection timeouts and keep your WordPress site running smoothly.
What Triggers a cURL Error 28 Timeout
First, it helps to understand what cURL is and when timeout errors occur:
cURL is the underlying library that handles HTTP requests in WordPress for things like plugins installs, analytics pings, social media APIs, ad networks, etc.
The “connection timed out” error appears when cURL cannot get a response to a request within the specified timeout period.
Common causes include:
- Network congestion
- Overloaded remote server
- Web host resource constraints
- DNS lookup delays
- Site code inefficiencies
Timeouts happen when external requests take too long to complete, either due to remote server problems or limitations on your own site’s server.
12 Potential Fixes for cURL Error 28
With the root cause in mind, here are 12 troubleshooting steps to overcome cURL timeout errors:
1. Increase PHP max_execution_time
The max_execution_time setting determines how long PHP scripts can run before timing out. Increase it to give cURL more time:
max_execution_time = 90
Just don’t use extremely high values that bog down your server.
2. Extend Apache/Nginx Request Timeout
Bump up the request timeout limit in your Apache or Nginx config. This allows more time per external request before terminating:
Again, find a reasonable timeout value that works for your site traffic.
3. Enable Non-Blocking I/O in PHP
Non-blocking I/O allows PHP to handle multiple cURL requests simultaneously without waiting. To enable:
- Install php-curl extension
- Set curl.multi_select to nonzero value in php.ini
This prevents a single slow connection from blocking others.
4. Optimize Database Queries
Inefficient database queries can hog resources needed for external cURL requests to complete. Optimize queries by:
- Adding indexes on frequently filtered columns
- Caching common queries with persistent object caching
- Enabling MySQL query cache
Optimized queries free up server resources for cURL.
5. Purge Unnecessary Data
Deleting outdated, unused data from WordPress can significantly improve performance:
- Remove stale transient options
- Clear out excessive revision posts
- Delete obsolete tables/records
A leaner database reduces query load and resource usage.
6. Limit Plugins and Themes
Too many plugins and themes can bog down WordPress with subpar code. Prune back to essentials:
- Disable unused plugins
- Switch to lighter theme
- Look for plugin/theme conflicts
Less to scan means quicker PHP execution.
7. Upgrade Web Hosting Plan
Shared hosts often impose resource limits that constrain cURL. Consider upgrading to:
- Dedicated server
- Managed WordPress hosting
- Cloud virtual machine
More resources results in faster cURL execution.
8. Enable Caching
Caching reduces server load by minimizing database queries. Use a persistent object cache and CDN:
- WP Rocket, WP Fastest Cache, etc.
Caching speeds up site performance for snappier cURL.
9. Adjust WordPress External Request Limits
WP limits concurrent external requests to avoid overwhelming servers. Tweak if needed:
- Increase WP_HTTP_MAX_REQUESTS
- Raise WP_CLI_MAX_ARGS
- Bump up WP_CLI_HTTPS_MAX_REQUESTS
Carefully test adjusted values to avoid unintended issues.
10. Check DNS Resolution
Latency resolving domain names can cause cURL delays. Ensure your DNS is performing well.
11. Monitor Performance with Debug Bar
Install the Debug Bar plugin and monitor page load times, queries, request concurrency, and more to isolate cURL bottlenecks.
12. Contact Hosting Provider
For managed WordPress hosts, inquire about server-level optimizations like CDNs, caching, load balancing, and improved resources allocation.
Avoid Future cURL Timeouts
Along with debugging specific issues, adopting cURL-friendly practices can prevent many timeouts:
- Choose robust WordPress hosting with quality infrastructure
- Only use essential plugins; limit resource-intensive ones
- Enable persistent caching
- Configure a content delivery network (CDN)
- Check for 3rd party service outages before troubleshooting site
- Monitor performance metrics and log cURL errors
- Keep WordPress and plugins updated
cURL timeout errors can certainly be frustrating. But some targeted troubleshooting to identify constraints combined with cURL-optimized hosting and site settings can eliminate most issues. Use the solutions in this guide to banish connection timeouts for good!
With the right mix of optimizations, upgrades, and performance monitoring, your WordPress site will have the resources for fast, reliable cURL execution without frustrating lag.