Understand and resolve timeouts impacting your users and availability
A server timeout occurs when an operation doesn't complete within the allotted time. It's a protection mechanism that prevents a stuck request from consuming resources indefinitely. For the user, this manifests as an error or a page that never loads.
Timeouts can occur at different stack levels: network connection, application processing, database queries, external service calls. Each level has its own timeout parameters and its own causes of exceeding. Identifying the concerned level is the first diagnostic step.
Effective monitoring allows detecting timeouts before they massively impact your users. MoniTao monitors your endpoint response times and alerts you when a timeout occurs or when response times approach critical thresholds.
Understanding the timeout type helps identify its cause and solution:
Timeouts generally have identifiable and fixable causes:
A methodical diagnosis allows quickly identifying the timeout cause:
Here are recommended timeout configurations for different layers of your stack:
# PHP - php.ini
max_execution_time = 30 ; Global script timeout
default_socket_timeout = 30 ; Timeout for file_get_contents, etc.
# PHP-FPM - pool.d/www.conf
request_terminate_timeout = 60 ; Kill worker after 60s
# Nginx - nginx.conf
proxy_connect_timeout 10s; ; Backend connection timeout
proxy_send_timeout 60s; ; Send to backend timeout
proxy_read_timeout 60s; ; Read from backend timeout
fastcgi_read_timeout 60s; ; PHP-FPM timeout
# MySQL - my.cnf
wait_timeout = 28800 ; Inactive connection timeout
interactive_timeout = 28800
lock_wait_timeout = 50 ; Lock wait timeout
# cURL in PHP
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // Connection
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // Total
These values are reasonable starting points. Adjust based on your needs: shorter for operations that should be fast, longer for legitimately long processes.
MoniTao helps you detect and diagnose timeout issues:
30 seconds is a good default for standard web operations. For legitimately long operations (exports, imports), create dedicated endpoints with higher timeouts. Don't increase the global timeout.
MoniTao has a configurable check timeout (default 30s). If your server doesn't respond within this time, MoniTao records a timeout and can trigger an alert based on your configuration.
Intermittent timeouts are often load-related: server handles normal traffic fine but saturates at peaks. Analyze temporal correlations between timeouts and traffic, deployments, or crons.
A resilience pattern that "opens the circuit" to a failing service after several failures, preventing cascading timeouts. After a delay, it tests the service again to see if it's restored.
Configure strict timeouts (5-10s max), implement circuit breakers, use caches for rarely changing data, and provide fallbacks (default values) when external service is slow.
If the proxy (Nginx) generates a 504, it's its timeout. If the application returns a timeout error, it's PHP or application timeout. Check both logs to identify which triggers first.
Timeouts are an essential protection mechanism but their triggering signals a performance issue. Resolution involves identifying the timeout type (connection, read, gateway), analyzing resources and logs, and optimizing slow operations.
Consistent timeout configuration across all stack levels is essential: proxy timeout should be higher than application's, which should be higher than database's. MoniTao allows you to monitor response times and be alerted before timeouts impact your users.
Start free, no credit card required.