Resolving cURL Error 28: Causes, Solutions, and Best Practices
ErrorsLearn what is causing the cURL error 28 timeout, how to troubleshoot the connection issues, and potential solutions in different environments.

Eugenijus Denisov
Key Takeaways
-
The cURL error 28 indicates that the connection timed out during the request or data transfer.
-
The error might occur due to timeout settings being set too low, firewalls or plugins, DNS resolution issues, and a host of other reasons.
-
Potential solutions include raising server limits, disabling interfering software, changing the DNS server, and updating systems.
Those who have used the cURL command-line tool for automation, web scraping, or other purposes for a while have probably encountered the cURL error 28 message. Receiving the former error message indicates that a timeout occurred when your website attempted to make an HTTP request to the server.
Understanding the common causes and solutions for this error will help you reduce such interruptions to your work.
What Does Error 28 Mean?
Using cURL, you might occasionally encounter a message indicating a timeout . One such error message goes, “cURL error 28: Operation timed out after 5000 milliseconds with 0 bytes received.”
It means the connection or data transfer dropped after exceeding the allowed time. In other words, because the HTTP request did not receive a response in the required time, it aborted the request and returned this message instead.
Common Causes of cURL Error 28
Server Timeout Settings
You might be seeing this timeout error message because one or more timeout settings are set too low.
PHP scripts have a maximum execution time. By default, this is 30 seconds. However, in many real-world scenarios, this might not be enough to get a response from a remote server. In this case, PHP stops the request, but it is often logged as error 28.
Secondly, libcurl has its own time limits. One such limit is the total time allowed for the request to complete. If this is set to, for example, 7 seconds, the data transfer must be fully complete by then. Otherwise, the connection times out, and the cURL error 28 occurs.
Another libcurl limit is the time allowed to establish the connection. During that time, DNS resolution, TCP handshake, and TLS negotiation must complete. If this limit is set to just 2 or 3 seconds, it might not be enough even to establish the connection.
Finally, your server or proxy HTTP request timeout settings may be set too low. Even if PHP and cURL limits are not exceeded, you might be informed that the connection timed out.
Importantly, your web hosting provider might be setting and enforcing harder limits than the default, causing connections to drop earlier than you would expect.
Firewall and Security Software
Firewalls can block legitimate requests by intercepting and stalling them until they time out. It is common in WordPress for a security plugin, such as Wordfence, to block a legitimate REST API request, resulting in a timeout error.
Similarly, hosting firewalls might be blocking requests, for example, due to rate limits, geolocation blocks, or other restrictions implemented by the web host. Since firewalls might block the request without returning any feedback, from the PHP/cURL side, it appears the connection timed out.
SMTP firewalls hosted by your hosting provider or an external service may also block requests from the SMTP plugin. If PHP sends code via email, it may be intercepted by the firewall and not respond until the error message informs you that the connection timed out.
One way to determine whether a firewall or security software is causing the error is to disable it temporarily. However, it might be that only your web host can do it.
DNS Resolution Issues
Slow or misconfigured DNS servers can interrupt connections, causing timeouts. To access a particular API or other web service, libcurl needs DNS to resolve the domain name to an IP address.
When DNS does not respond or responds slowly, the connection times out, and you receive cURL error 28. As in previous cases, this may be caused by firewalls or rate limits imposed by the web host. Alternatively, the DNS server may be offline or overloaded.
A few methods will help you troubleshoot if the DNS server is causing the problem. First, test DNS resolution from the server. You open your terminal and use this code snippet to check for DNS resolution:
nslookup api.example.com
If the log shows long response times, timeouts, or no answer, DNS is causing the cURL 28 error.
Secondly, you can check the public DNS servers, such as Cloudflare’s 1.1.1.1 or Google’s 8.8.8.8.
dig api.example.com @1.1.1.1
dig api.example.com @8.8.8.8
If the resolution is fast with these servers, your original DNS server is to blame for the timeout.
Finally, you can bypass DNS and test a raw IP connection.
curl https://93.184.216.34
DNS is at fault if the IP address works but the hostname doesn’t. If you have determined that DNS is the source of the issue and want to change the DNS server indeterminately, you can do the following. First, check the status.
resolvectl status
You’ll see various interfaces, such as eth0. Set DNS servers per interface.
sudo resolvectl dns eth0 1.1.1.1 8.8.8.8
sudo resolvectl domain eth0 "~."
Finally, flush the cache. After that, your new server settings should survive reboots.
sudo resolvectl flush-caches
You can also check the status again to verify the change.
SSL Configuration Problems
SSL misconfiguration can lead to timeouts instead of clear SSL errors when the TLS handshake is initiated but never completes.
When packets are dropped mid-handshake, the client might silently retry, without sending a TLS alert. Libcurl eventually reports that the connection timed out, with a cURL error 28.
Often, certificate issues cause stalled handshakes, which lead to timeouts. For example, a missing intermediate certificate will cause the handshake to hang without failing, until it times out. Additionally, an expired or invalid certificate can cause TLS verification delays and ultimately result in a curl error 28.
Other SSL issues can also cause this error, such as unsupported TLS versions or ciphers, or SNI misconfiguration.
Plugin Conflicts and Application-Specific Issues
Poorly written code in plugins or applications might sabotage cURL requests, resulting in cURL error 28. Poor application-layer timeout logic might cut off many requests. Bad code can lock cURL in heavy loops of asynchronous requests. Similarly, improperly handled redirects might create an infinite redirect loop .
All these issues are especially common in plugin-heavy environments, such as WordPress.
Troubleshooting and Fixes Across Different Environments
Fixing cURL Error 28 in WordPress
In WordPress, the cURL error 28 will usually appear in the Site Health section under the heading “The REST API encountered an error. You can identify the cause of cURL error 28 and resolve it by gradually checking for the potential issues outlined above.
Step 1: Temporarily disable firewall plugins to see if the issue persists. If it disappears, you know that the firewall is causing the error. You can switch to a different plugin or contact the plugin developer to see if the problem can be solved. Step 2: If the firewall plugin is not the cause, deactivate other plugins one by one until you find the culprit. Step 3: Check SSL certificates to ensure they are valid at this time and none are missing. Step 4: Review server limits. Extend them yourself or contact your web host if necessary. Step 5: Check whether the DNS server resolves properly. If not, try switching to a reliable public DNS server. Alternatively, contact your hosting provider to see if they can fix the DNS server issues.
Resolving cURL Timeout in Email (SMTP) Context
SMTP traffic is heavily filtered to prevent malicious emails and spam. Your web host might be blocking specific ports or outbound SMTP by default.
To see whether the SMTP firewall is causing the error, check local firewall rules for rate limits or outbound blocks.
sudo iptables -L -n
Additionally, it is important to use the latest versions of PHP and cURL, as older versions often lack modern TLS support and fail to support SMTP STARTTLS. Update your cURL library and PHP, then check whether cURL error 28 persists.
If this doesn’t help, try increasing timeout settings. SMTP requests take longer than HTTP requests. Therefore, it is recommended to allow at least 30 seconds for the entire execution.
Finally, when the issue is caused by server-side settings or firewalls controlled by your web host, contacting them is your last resort.
Developer and Composer Environment Fixes
If nothing else works and you keep receiving cURL error 28 even though everything seems configured correctly, there are a few fixes you can try.
As mentioned, it is important to flush the DNS cache. DNS might be cached with the wrong IP or a partial update, silently causing the connection to time out even though everything seems in order.
Another potential fix is to ignore system requirements when installing Composer. System requirements describe the minimum features your system must provide for the packet to work. When they are not met, Composer may fall back to slower code paths. This leads to inconsistencies that eventually result in timeouts.
This is how you tell Composer to ignore platform requirements in Bash.
composer install --ignore-platform-reqs
Note that this is not a permanent fix. If it works, it means there is a mismatch in your PHP, cURL, and/or OpenSSL versions.
Another potential reason you are still seeing the error is that the MTU is too large and the packet is fragmented during transmission. This is often the case with Docker MTU, which usually should not exceed 1400.
If Docker MTU is too large and mismatched with the Host or Overlay MTU, you can reduce it.
{
"mtu": 1400
}
Restart Docker:
sudo systemctl restart docker
Finally, the VPN you are using might be interfering with your transmissions. Test with the VPN off to see if you still get the cURL error 28. If the error stops, avoid using VPNs. Use firewall rules instead.
In Conclusion
The cURL error 28, “connection timed out,” is a common issue with the cURL command-line tool. The bad news is that many issues at various layers might be causing it. The good news is that, in many cases, you can implement fixes without your web host.
Sometimes, however, when the web host enforces settings, you will need their cooperation to stop the timeouts. Even then, a reputable web host should help you resolve the issues and get your automation working properly.
FAQ
Can firewall settings cause cURL error 28?
Yes. Firewalls might intercept legitimate requests, for example, when they find the agent (cURL or PHP) suspicious, delaying the request and causing the timeout.
How can I test if DNS is causing cURL error 28?
Try accessing it directly by IP address or resolving it with a public DNS server, such as 8.8.8.8. If both methods work, but the error occurs when you use your local DNS server, it is likely the source of the issue.
Is cURL error 28 related to SSL certificate problems?
Yes, outdated certificates, as well as those that become valid later, might cause timeout issues. When one of the certificates is missing, this could also lead to error 28.