In short
A 504 Gateway Timeout means: an intermediary server waited too long for a response and aborted the request. The page is not broken - a process behind it simply takes too long.
What does status code 504 mean?
As with 502, a web server, proxy or CDN is involved as an intermediary. With 504, however, the application server's response is not faulty but too late: the waiting time ran out before the script had finished.
Typical causes
- Compute-intensive scripts, such as imports, exports or generating many images
- Slow database queries, for example on large tables without suitable indexes
- External services your site queries that respond slowly themselves - interfaces, payment or shipping services
- Heavy background tasks that run along with a normal page view - such as WP-Cron in WordPress
- With an upstream proxy or CDN: a shorter waiting time there than on the server
Solution for visitors
- Reload the page after a moment.
- If the error occurs during a specific action, such as submitting a form, check whether the action was carried out after all before trying again.
- Let the operator know if the error occurs repeatedly.
Solution for site operators
- Find the slow process: which address is affected, and does it always happen or only occasionally? The access and error logs help with this (reading log files).
- Move long tasks elsewhere: run imports, exports, newsletters or reports via cron job or SSH instead of in the browser. In WordPress, replace WP-Cron with a real cron job.
- Optimise the database: clean up clutter such as revisions or expired entries and check slow queries from plugins.
- Safeguard external services: set short time limits for interface calls and cache their responses.
- Use caching: a page cache and - from the Premium plan upwards on request - Redis as an object cache significantly shorten response times. With ShieldCache, pages are served straight from the Varnish cache, and our CDN delivers static files from locations close to your visitors.
- Check the PHP time limit: you can adjust individual settings such as
max_execution_timewith your own php.ini. However, this does not remove the cause - the page only becomes faster through the optimisation itself.
Related status codes
- 502 Bad Gateway - invalid response from an upstream server
- 503 Service Unavailable - temporarily unavailable
- 500 Internal Server Error - general server error
- All status codes at a glance