A brief explanation
A 504 Gateway Timeout means that an intermediary server has waited too long for a response and has abandoned the request. The page isn’t broken - it’s simply that a process behind the scenes is taking too long.
What does status code 504 mean?
As with the 502, a web server, proxy or CDN is involved as an intermediary. With a 504, however, the response from the application server is not faulty, but simply late: the time-out occurred before the script had finished.
Typical causes
- Computationally intensive scripts, such as imports, exports or the generation of large numbers of images
- Slow database queries, for example when dealing with large tables without suitable indexes
- External services that your site queries and which themselves respond slowly - interfaces, payment or delivery services
- Resource-intensive background tasks that run whilst a page is being loaded - such as WP-Cron in WordPress
- If a proxy or CDN is in place: a shorter wait time there than on the server
Solution for visitors
- Refresh the page after a moment.
- If the error occurs during a specific action, such as submitting a form, check whether the action was actually carried out before trying again.
- Please inform the site operator if the error occurs repeatedly.
Solution for website operators
- Identify the slow process: Which URL is affected, and does it happen all the time or only occasionally? The access and error logs can help with this (analyse log files).
- Outsource time-consuming tasks: Run imports, exports, newsletters or reports via cron jobs or SSH rather than in the browser. In WordPress, replace WP-Cron with a proper cron job.
- Optimise the database: Clear out legacy data such as revisions or expired entries, and check for slow queries from plugins.
- Secure external services: Set short time limits for API calls and cache their responses.
- Use caching: Page caching and - available on request from the Premium plan onwards - Redis as an object cache significantly reduce response times. With ShieldCache, pages are served directly from the HTTP cache, whilst our CDN delivers static files from locations close to your visitors.
- Check the PHP timeout: Individual settings such as
max_execution_timecan be customised via a dedicated php.ini file. However, this does not address the root cause - the page will only become 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
- An overview of all status codes