Troubleshooting · Explainer
What Causes the 504 Gateway Timeout Error in WordPress?
Short answer
A 504 Gateway Timeout error means a gateway or proxy waited for the server behind it and got no answer in time. In WordPress that usually means a script ran past the PHP execution time limit, a slow database query held the request, the server was too busy to answer, or a remote call hung. The gateway is up and the origin is reachable, but the origin was too slow.
Key takeaways
- A 504 is a timing fault: the gateway waited and got no answer in time.
- The typical PHP limit is 30 seconds, shown by the message Maximum execution time exceeded.
- A 504 on one heavy action points at that action, not at the whole site.
- A slow query holds a PHP worker, so the gateway can time out before the page is built.
- A proxy timeout shorter than the origin needs will cause a 504 even when WordPress is fine.
What does a 504 Gateway Timeout error mean in WordPress?
A 504 Gateway Timeout error means a gateway or proxy waited for the upstream server and got no response in time.
MDN defines the 504 status this way and adds that it is similar to a 502, except that in a 504 the gateway received no HTTP response from the origin within a set time (MDN 504 status).
On a WordPress site the gateway is usually Nginx, a load balancer, or a CDN edge server. WordPress runs behind it on PHP. When a PHP script takes longer than the gateway is willing to wait, the gateway gives up and answers with a 504.
That is the key clue. A 504 is a timing fault, not a crash fault.
The origin is there, but it was too slow. A 502, by contrast, means the gateway got a bad response or none at all because the origin failed.
What causes a 504 error on a WordPress site?
The most common WordPress causes are a script that passes the PHP execution time limit, a slow database query, an overloaded server, and a remote call that hangs.
The PHP execution time limit is the first cause. PHP stops a script that runs longer than max_execution_time, and the WordPress common errors guide gives “Maximum execution time of 30 seconds exceeded” as the typical message. A large import, a backup, or a migration can easily pass 30 seconds on shared hosting.
Slow database queries are the second cause. A query that scans a large table without an index, or a bloated wp_options table full of autoloaded rows, can hold a request for many seconds. The page eventually loads or dies, but the gateway may time out first.
An overloaded server is the third cause. When every PHP worker is busy, a new request waits in line and may pass the gateway timeout before a worker frees up.
The WordPress common errors guide describes this pattern as a site trying to do more than the server can manage, common on shared hosting with a restricted memory limit.
A remote call that hangs is the fourth cause. A plugin that contacts an external API, a license server, or a payment gateway on every page load will stall the whole request if that service is slow.
WordPress also makes remote calls for update checks and feeds, and a slow answer there can delay admin pages in particular.
How can you tell which cause you have?
Start by timing the error and noting which pages or actions trigger it.
A 504 that appears after the same number of seconds every time points at a fixed timeout, such as the 30-second PHP limit or a gateway timeout. A 504 that appears only on one action, such as an import or a backup, points at that action being too slow.
| Clue | Likely cause | Where to check |
|---|---|---|
| Error after about 30 seconds | PHP max_execution_time hit | PHP error log |
| Only imports, backups or migrations fail | Slow action, too little time | Error log, host limits |
| Error only in wp-admin | Slow remote call or cron task | Debug log, Query Monitor |
| Error under traffic, all pages | Overloaded server, full worker pool | Host CPU and worker stats |
| Error only on one page | Slow query on that page | Query log, database size |
| Error after a plugin update | Plugin making a slow remote call | Error log, plugin folder |
If the error log shows “Maximum execution time exceeded” with a file and line number, the cause is a slow script and the log names it. If the log is empty, the gateway may have timed out before PHP logged anything, which points at the server or the gateway settings.
The fix steps for the WordPress side are in our guide on how to fix the 504 Gateway Timeout error.
What does the error log tell you about a 504?
The PHP error log usually names the script and line where time ran out, which is the fastest route to the cause.
WordPress writes PHP errors to wp-content/debug.log when WP_DEBUG and WP_DEBUG_LOG are true in wp-config.php, with WP_DEBUG_DISPLAY set to false so errors stay out of the page HTML (WordPress debugging handbook).
The handbook warns that these constants must go before the line that reads “That's all, stop editing! Happy blogging.” in wp-config.php, and that WP_DEBUG is meant for local or staging use rather than a live site.
A log line that says “Maximum execution time of 30 seconds exceeded” names the file and line where the script stopped. If that file sits in a plugin folder, the plugin is the cause. If it sits in a theme folder, the theme is the cause.
A log with no entries at the time of the error is also useful. It suggests the gateway timed out while PHP was still running, or that the server never passed the request to PHP.
In that case the host's server log and the gateway timeout setting matter more than WordPress. A related timeout in the admin area is covered in our guide on how to fix cURL error 28.
Why does the PHP execution time limit cause a 504?
The PHP execution time limit causes a 504 because PHP kills a slow script while the gateway is still waiting for an answer.
PHP's max_execution_time setting caps how long a script may run. The WordPress common errors guide shows the two ways to raise it: add max_execution_time = 60 to php.ini, or add php_value max_execution_time 60 to .htaccess. Both need a backup of the file first.
When the limit is hit, PHP stops the script with a fatal error. If the script was building the page, no page is sent. The gateway, which was waiting for a response, reaches its own timeout and answers with a 504.
The clue is the fixed delay. If the error always appears after the same number of seconds, a timeout is doing it. Raising the limit helps a slow import finish, but a script that is slow because of a bad query will still be slow.
The common errors guide lists raising the limit alongside deactivating plugins and switching themes, so the limit is one suspect among several, not the whole answer. Our guide on how to fix Maximum Execution Time Exceeded covers the fix in full.
How do slow queries and overloaded servers cause a 504?
Slow queries and overloaded servers cause a 504 by making a request take longer than the gateway is willing to wait.
A slow query holds a PHP worker while the database works. A query without an index can scan hundreds of thousands of rows, and a wp_options table with many autoloaded rows loads on every request. The page may still finish, but only after the gateway has given up.
An overloaded server causes the same wait in a different way. When every PHP worker is busy, a new request queues. The gateway timeout counts from the moment the request arrived, not from when PHP started it, so a queued request can time out before it runs at all.
WordPress.org recommends PHP 8.3 or greater and MySQL 8.4 or MariaDB 10.11 or greater as of November 2026 (WordPress requirements). A site on far older versions can be slower, and a slow database makes every timeout more likely.
The host control panel usually shows CPU, memory and database load. A graph that peaks at the same time as the errors confirms overload. If CPU use is the limit, our guide on how to fix high CPU usage covers the WordPress side.
How do proxies and CDNs cause a 504?
A proxy or CDN causes a 504 when its own timeout is shorter than the time the origin needs to answer.
Cloudflare, Nginx and load balancers each have a timeout for waiting on the origin. If WordPress needs 60 seconds for an import but the proxy waits only 30, the proxy answers with a 504 even though WordPress would have finished. The origin is not broken; the proxy is impatient.
Cloudflare's 5xx guide notes that the cause of a 5xx error is not always in the origin server's own logs, and the logs of load balancers, caches, proxies and firewalls between Cloudflare and the origin should also be checked (Cloudflare 5xx errors).
The test is to load the same slow action without the proxy, if the host allows it. If it finishes directly but fails behind the proxy, the proxy timeout is the cause. If it fails directly too, the origin is too slow and the proxy is only reporting it.
MDN adds one exception: client network errors, mostly when the site works for other visitors and the visitor uses a VPN or custom network setup (MDN 504 status). If only you see the 504, try another network before changing the server.
What mistakes should you avoid?
Do not raise timeouts again and again instead of finding why the request is slow.
A higher limit lets a slow import finish, but it also lets a bad query hold a PHP worker longer, which can make overload worse. The WordPress common errors guide lists raising the limit as one step, next to deactivating plugins and switching to a default theme, not as a cure on its own.
Do not run heavy actions during peak traffic. Imports, backups and migrations are the actions most likely to hit a timeout, and running them when the site is quiet gives them the full worker pool.
Do not ignore the error log. A log line that names the file and line where time ran out is worth more than any guess. Without it, you may raise the wrong limit or blame the wrong plugin.
Finally, do not confuse a 504 with a 502. A 502 means the gateway got a bad response, while a 504 means it got no response in time.
The two point at different faults, so check the code before acting. A slow admin dashboard has its own causes, covered in our guide on how to fix a slow admin dashboard.
Frequently asked questions
What is the difference between a 504 and a 502 error?
A 502 means the gateway got an invalid response from the server behind it, while a 504 means the gateway got no response in time. A 502 often means PHP crashed or the origin is down, while a 504 often means a slow script, a slow query, or a busy server. Check the error log to see which one applies.
Can a 504 error fix itself?
Sometimes, if the cause was a brief traffic spike or a slow remote service that recovered. If the error repeats on the same action, it will not clear on its own. A script that always passes the 30-second limit needs a fix, either a faster query, a disabled plugin, or a higher limit.
Can a proxy or CDN cause a 504 even when WordPress is fine?
Yes. Cloudflare and other proxies have their own timeout for waiting on the origin, often shorter than the time a heavy WordPress action needs. If the action finishes when you load it directly but fails behind the proxy, the proxy timeout is the cause. Ask the host about the gateway timeout setting.
How long does PHP let a script run before timing out?
Usually 30 seconds, which is why the WordPress error guide quotes the message Maximum execution time of 30 seconds exceeded. Hosts can set it higher or lower, and some hosts set it in php.ini, .htaccess or the control panel. Check the error log for the exact limit your server reports.
Should I contact my host about a 504 error?
Yes, if the error is site-wide, repeats under traffic, or the action fails even without the proxy. Give the host the error code, the time and timezone, the failing URL, and the last lines of your error log. That detail lets them check the gateway timeout and the server logs you cannot see.
Sources
- 504 Gateway Timeout MDN Web Docs
- Common WordPress Errors WordPress Developer Resources
- Debugging in WordPress WordPress Developer Resources
- Cloudflare 5xx errors Cloudflare Docs
- Requirements WordPress.org
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
