A 504 gateway timeout in WordPress means your server was still working on the page, but it took too long, so the server in front of it stopped waiting. Nothing crashed. Something was slow: a plugin, a database query, an outside API or a long task. Find which timeout ran out first, catch the slow request, then fix that cause. WPOptimizers can do it for you.
Most 504 guides tell you to raise the timeout and move on. That can hide the problem for a while, but the slow request is still slow, and behind a CDN like Cloudflare, raising limits past a certain point does nothing at all.
This guide shows you how to find the request that hung. It covers what most guides skip, like the stack of timers on every request, the PHP-FPM slow log that names the exact plugin, and the difference between a server 504 and a Cloudflare 524.
How Do You Fix A 504 Gateway Timeout In WordPress?
Fix a 504 gateway timeout by first finding which layer timed out, then finding the slow request in your logs. Disable heavy plugins, clean up slow database queries, check PHP workers and server resources, line up your timeout settings, and move long tasks out of normal page requests. WPOptimizers follows this order on every 504 repair.
Here are the 8 fixes, in the order to try them:
- Reload the page and check whether it’s only you
- Find which layer timed out
- Find the slow request in your logs
- Disable plugins and switch the theme
- Speed up slow database queries
- Check PHP workers and server resources
- Line up your timeout settings
- Move long tasks out of the page request
Take a backup before you change files or settings. If anything goes wrong, here’s how to restore WordPress from backup.
What Is The 504 Gateway Timeout Error?
The 504 gateway timeout error is an HTTP status code. It means a server acting as a gateway or proxy didn’t get a response from the server behind it in time. On WordPress, that’s usually nginx or Apache waiting on PHP-FPM, which is still busy running a slow script or database query.
A typical request travels like this:
Browser → CDN (Cloudflare) → Web server (nginx or Apache) → PHP-FPM → MySQL database
Each link has its own timer. If PHP takes 90 seconds and nginx only waits 60, nginx gives up at 60 and shows a 504, even though PHP may finish the job a moment later.
You may see it as:
- 504 Gateway Timeout
- 504 Gateway Time-out nginx
- HTTP Error 504
- Gateway Timeout Error
They all mean the same thing: a response took longer than the proxy was willing to wait.
How Is A 504 Different From 502, 503 And 524 Errors?
These errors look alike but point to different problems. The code tells you whether PHP crashed, was overloaded, or was simply too slow. A 502 means PHP failed, while a 504 means PHP was alive but didn’t answer in time. Knowing which one you have saves you from trying the wrong fixes.
| Error | What It Means | Where To Look First |
| 502 Bad Gateway | The proxy got a broken or empty reply | PHP-FPM crashes, error log |
| 503 Service Unavailable | The server is overloaded or in maintenance | Traffic, resource limits, maintenance mode |
| 504 Gateway Timeout | Your server’s proxy waited too long for PHP | Slow scripts, slow queries, timeouts |
| Cloudflare 524 | Cloudflare waited 100 seconds for your server | Requests that run longer than 100 seconds |
If you’re seeing a 500 instead, read how to resolve the 500 internal server error in WordPress. If the page says “Error establishing a database connection,” here’s how to fix the error establishing a database connection.
Fix 1: Reload The Page And Check Whether It’s Only You
Reload the page after a minute, then try a private window, another browser or mobile data. If it loads elsewhere, clear your browser cache and flush your DNS cache. If it times out everywhere, the problem is on the server. Note which page failed, because a 504 on one admin action has a different cause from a 504 on every page.
To flush DNS on Windows, open Command Prompt and run:
ipconfig /flushdns
On macOS, run:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
A 504 that appears once and disappears on reload usually came from a short traffic spike or a one-off slow task. If it keeps coming back, keep going.
Fix 2: Find Which Layer Timed Out
Look at the error page. A Cloudflare page showing 524 means Cloudflare waited 100 seconds and gave up. A plain “504 Gateway Time-out nginx” page means your own server’s timer ran out first. If the error always appears at a round number, like 30 or 60 seconds, that’s your server’s limit. WPOptimizers checks this first on every 504 case.
| What You See | Which Timer Ran Out | Start Here |
| Cloudflare 524 page | Cloudflare’s 100-second limit | Requests running over 100 seconds (Fix 8) |
| Cloudflare 504 page, host marked as the problem | Your server’s proxy | Logs and timeouts (Fixes 3 and 7) |
| Plain “504 Gateway Time-out nginx” | Nginx’s read timeout | PHP-FPM slow log (Fix 3) |
| Your host’s branded timeout page | Your host’s proxy or load balancer | Hosting support |
Timing helps too. Open your browser’s developer tools, go to the Network tab and reload. The time before the error shows which limit was hit.
Fix 3: Find The Slow Request In Your Logs
Open the server error log from cPanel, hPanel, Plesk or your host’s dashboard and check entries from the time of the error. A line with “upstream timed out” confirms the 504 and shows the URL that was slow. Then check the PHP-FPM slow log, which names the exact file and function that was running when time ran out.
| Log Line Contains | What It Means | Fix |
| upstream timed out (110) while reading response header | PHP was too slow to answer | Find the slow script or query (Fixes 4 and 5) |
| upstream timed out (110) while connecting to upstream | PHP-FPM was too busy to accept the request | Check PHP workers and traffic (Fix 6) |
| executing too slow (in the PHP-FPM log) | A request passed the slow log limit | Read the slow log trace |
| server reached pm.max_children setting | All PHP workers are busy | Add caching or more workers (Fix 6) |
| request_terminate_timeout / terminated | PHP-FPM killed a long request | Find what made it run so long |
On a VPS, you can turn on the PHP-FPM slow log in your pool config (often /etc/php/8.3/fpm/pool.d/www.conf):
request_slowlog_timeout = 10s
slowlog = /var/log/php-fpm-slow.log
Restart PHP-FPM, wait for the 504 to happen again, then open the slow log. The trace usually shows a path like wp-content/plugins/plugin-name/, which tells you exactly what to fix. On shared or managed hosting, ask support to check the slow log for you.
Fix 4: Disable Plugins And Switch The Theme
Plugins that call outside services, run heavy reports or process large files can keep PHP busy past the timeout. Disable all plugins by renaming the plugins folder. If the 504 stops, rename it back and re-enable them one by one to find the cause. WPOptimizers checks plugins that call external APIs first.
Using FTP or File Manager, go to wp-content and rename the plugins folder to plugins-off. If you have SSH access, you can run this instead:
wp plugin deactivate --all
Common plugin causes of 504s:
- Social feeds, currency or stock widgets waiting on slow external APIs
- Broken link checkers and SEO crawlers scanning the whole site
- Page builders saving very large pages
- Security scans or backups running during the day
- WooCommerce reports and bulk edits on big stores
If plugins aren’t the cause, rename your active theme’s folder inside wp-content/themes to switch to a default theme. The free Query Monitor plugin shows slow queries and slow HTTP calls on any page you can load, which helps when the 504 only happens sometimes. Keep plugins current with this safe plugin update process.
Fix 5: Speed Up Slow Database Queries
A bloated wp_options table, huge postmeta tables or old WooCommerce data can make simple queries take seconds. PHP waits for MySQL, and the proxy waits for PHP until it times out. Cleaning and optimizing the database usually brings response times back down. WPOptimizers checks autoloaded data on every slow site.
Check how much data WordPress loads on every request with this query in phpMyAdmin (change wp_ if your table prefix is different):
SELECT SUM(LENGTH(option_value)) AS autoload_bytes
FROM wp_options
WHERE autoload IN ('yes', 'on', 'auto-on', 'auto');
A result well over 1 MB is a warning sign. Other things to clean up:
- Old post revisions, spam and trashed comments
- Expired transients left behind by plugins
- Leftover tables from plugins you removed
- Old WooCommerce sessions and Action Scheduler logs
Always take a backup before deleting anything from the database.
Fix 6: Check PHP Workers And Server Resources
If 504s show up only at busy times, your server may be short on PHP workers, CPU or RAM. Requests queue up waiting for a free worker, and the proxy times out before they even start. Page caching, blocking bad bots and a bigger plan all help. WPOptimizers checks resource graphs before raising any limit.
Signs of a resource problem:
- 504s appear during traffic spikes or sales, not at quiet hours
- CPU or RAM in your hosting panel sits near 100%
- Logs show “pm.max_children” or “while connecting to upstream”
- Bots hit wp-login.php, xmlrpc.php or search pages heavily
If workers are being stopped for using too much memory, raise the WordPress memory limit. If your plan can’t keep up with your traffic, compare the best WordPress hosting for speed.
Fix 7: Line Up Your Timeout Settings
Raise timeouts only after you’ve found the slow request, and only by a reasonable amount. Several timers sit on each request, and the shortest one always wins. Raising one limit does nothing if a shorter one is still in place, and behind Cloudflare nothing helps past 100 seconds. WPOptimizers sets these to match each other.
| Timer | Where It Lives | Common Default | What Happens When It Runs Out |
| Proxy read timeout | Cloudflare | 100 seconds (fixed below Enterprise) | Error 524 |
| fastcgi_read_timeout | Nginx | 60 seconds | 504 Gateway Timeout |
| ProxyTimeout / Timeout | Apache | Depends on host setup | 504 Gateway Timeout |
| max_execution_time | PHP (php.ini) | 30 seconds | PHP fatal error, often a 500 |
| request_terminate_timeout | PHP-FPM pool | Off unless your host sets it | Worker killed, often a 502 |
On a VPS with nginx, the setting goes in your site’s PHP location block:
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
fastcgi_read_timeout 90s;
include fastcgi_params;
}
And in php.ini:
max_execution_time = 90
Then reload both services:
sudo systemctl reload nginx
sudo systemctl restart php8.3-fpm
On Plesk, add fastcgi_read_timeout under the site’s Apache & nginx Settings, in the additional nginx directives field. On shared or managed hosting, you usually can’t change these, so ask your host. If your site is behind Cloudflare, keep these values under 100 seconds so your server fails with a clear error in your own logs instead of an unexplained 524.
Still Getting 504 Timeouts?
If your site keeps timing out, or you’d rather not dig through server logs, WPOptimizers WordPress developers can find the slow request, clean up the database and tune your server so pages load fast again.
Fix 8: Move Long Tasks Out Of The Page Request
Tasks that need minutes, like large imports, exports, backups or bulk edits, shouldn’t run inside a normal page request. Run them with WP-CLI over SSH, break them into smaller batches, or let them run in the background through a real server cron job. WPOptimizers moves these jobs off peak hours on every site it manages.
WP-Cron runs when someone visits your site, so a heavy scheduled task can slow down a real visitor’s page. Switch it to a real server cron by adding this to wp-config.php:
define( 'DISABLE_WP_CRON', true );
Then create a cron job in your hosting panel that calls wp-cron.php every 5 or 15 minutes. If you skip this step, scheduled posts and backups will stop running.
For imports and exports, most good plugins let you set a batch size. Smaller batches finish within the time limit and still get the whole job done.
Does A 504 Error Hurt Your SEO?
A short 504 doesn’t hurt SEO, because search engines treat 5xx errors as temporary. If timeouts continue for days, Google may slow crawling and start dropping affected pages. Repeated 504s also show up as server errors in Search Console. WPOptimizers treats any 504 that keeps coming back as urgent.
Slow pages that don’t quite time out still cost you, because they hurt user experience and crawling. After the fix, open Search Console, check the Page indexing report for server errors (5xx), and request reindexing for important pages.
How Do You Stop 504 Errors From Coming Back?
Stop repeat 504 errors by keeping page and object caching active, cleaning the database regularly, moving heavy jobs to server cron, keeping timeout settings aligned, and monitoring uptime. Most 504s return because the slow request was never fixed, only hidden behind a higher limit. WPOptimizers’ maintenance plans cover all of these.
A simple prevention checklist:
- Set up uptime monitoring with alerts so you know within minutes
- Keep the PHP-FPM slow log on at a sensible limit, such as 10 seconds
- Clean revisions, transients and autoloaded options every few months
- Run imports, backups and scans outside peak hours
- Test new plugins on staging before adding them to the live site
- Keep daily backups so you can roll back fast
WordPress maintenance plans from WPOptimizers start at $49 per month and handle monitoring, safe updates and daily backups for you.
Frequently Asked Questions About The 504 Gateway Timeout Error
These answers cover the questions site owners ask most about the 504 gateway timeout in WordPress, including who’s responsible, admin-only timeouts, PHP limits, Cloudflare 524 and when to call your host, based on how WPOptimizers fixes client websites.
Is A 504 Error My Fault Or My Host’s?
It can be either. Slow plugins, heavy pages and a bloated database are on the site side. Overloaded hardware, too few PHP workers or a strict proxy timeout are on the host side. The slow log usually shows which one it is.
Why Do I Only Get A 504 In wp-admin Or During Imports?
Admin tasks like imports, exports, bulk edits and page builder saves do much more work than loading a cached front-end page. They often pass the time limit while normal pages load fine. Run these tasks in smaller batches or through WP-CLI.
Will Increasing max_execution_time Fix A 504?
Not on its own. A 504 comes from the web server’s proxy timeout, not PHP’s limit. If nginx still waits only 60 seconds, raising PHP’s limit changes nothing. Behind Cloudflare, anything over 100 seconds still ends in a 524.
What Is The Difference Between A 504 And Cloudflare Error 524?
A 504 means your own server’s proxy, like nginx, gave up waiting on PHP. A 524 means Cloudflare reached your server, but your server took longer than 100 seconds to reply. Both mean something is too slow, but the fix starts in different places.
How Long Does A 504 Error Last?
A 504 from a short traffic spike or a one-off slow task can clear in minutes. One caused by a slow plugin, a bloated database or a timeout that’s set too low comes back every time that request runs, until the cause is fixed.
Should I Contact My Host About A 504 Error?
Yes, if you can’t access server logs, can’t change timeout settings, or the error appears across your whole site. Share the exact time, the URL that failed and any log lines you found. That helps support find the slow request faster.
Keep Your WordPress Site Fast And Online
WPOptimizers WordPress maintenance plans start at $49 per month, with managed updates, daily backups and site monitoring, so slow plugins and server issues are caught early, before they turn into timeouts.