Skip to content
Website Rescue Rescue

Server Errors

504 Gateway Timeout

Intermediate Risk: medium

Last reviewed

Hosting access often needed Database access usually not needed

Direct answer

504

A 504 Gateway Timeout means a proxy or gateway gave up waiting for an upstream response — often slow PHP, a stuck database query, exhausted workers, or a CDN/origin timeout — not a missing page. Confirm the real status code, find what is hanging in logs, then fix the slow upstream rather than only raising timeouts.

HTTP 504 is a waiting failure between layers (nginx → PHP-FPM, load balancer → app, CDN → origin). On WordPress it usually traces to heavy plugins, slow MySQL, or under-provisioned workers. This guide separates 504 from 502 and Cloudflare 522/524 so you chase the right layer instead of random theme tweaks.

Intermediate

What the error means

A gateway sits between the client and the process that should generate the page. When that upstream does not answer within the gateway’s limit, the gateway returns 504. Classic pairs include reverse proxy → PHP-FPM, Apache → backend, or CDN → origin. That is different from 502 (bad or empty upstream response), Cloudflare 522 (TCP connection to origin never completed), and Cloudflare 524 (TCP connected but the HTTP response was too slow at Cloudflare’s limit). WordPress rarely “throws” 504 itself — PHP or MySQL simply never finishes in time, so the proxy times out.

Common symptoms

  • Visitors see “504 Gateway Timeout” or a host/CDN branded timeout page
  • Heavy pages (checkout, search, admin, exports) fail while light pages sometimes load
  • DevTools shows status 504; TTFB climbs until the gateway cuts off
  • PHP slow logs or MySQL processlist show long-running queries during the outage
  • Problem worsens under traffic or during cron, imports, or backups
  • Site works when the CDN is bypassed but times out through the edge (or the reverse)
  • Intermittent timeouts that clear after a few minutes when workers recover

Most likely causes

  1. 01 PHP script or plugin taking longer than the proxy/FastCGI read timeout
  2. 02 Slow or locked MySQL queries blocking page generation
  3. 03 PHP-FPM or app workers exhausted — requests queue until the gateway times out
  4. 04 CDN or load-balancer origin read timeout shorter than legitimate page work
  5. 05 External API calls from WordPress hanging without sane client timeouts
  6. 06 Runaway cron, import, or backup jobs saturating CPU and database
  7. 07 Misconfigured upstream sockets (wrong PHP-FPM pool or dead backend) presenting as timeouts

What changed before the problem started

  • Plugin, theme, or WooCommerce update that added heavy queries
  • Traffic spike, sale, or bot flood saturating workers
  • CDN, Cloudflare, or host proxy timeout settings changed
  • Database growth, missing indexes, or a stuck migration/import
  • PHP version or FPM pool size change reducing capacity
  • New external API, ERP, or shipping integration on checkout

Troubleshooting steps

  1. 01

    Confirm 504 and distinguish 502 / 522 / 524

    In DevTools → Network, read the exact status and response body. 504 is gateway wait timeout. 502 usually means a bad upstream response. Cloudflare 522 is origin connection timeout; 524 is connected but response too slow at Cloudflare. Screenshot Ray IDs or host error pages — the code decides whether you fix PHP/MySQL, origin reachability, or edge timeouts.

  2. 02

    Bypass CDN briefly and retest the origin

    Grey-cloud the DNS record or hit the origin with the correct Host header. If origin is fast and only the CDN times out, raise or align edge/origin timeouts and cache HTML correctly. If origin itself 504s, ignore the CDN until PHP and MySQL are healthy.

  3. 03

    Read PHP slow logs and host error logs at the timestamp

    Find which script, plugin path, or upstream timed out. Slow-log entries pointing at a plugin or `admin-ajax.php` beat guessing. Note whether timeouts cluster on one URL or every request.

  4. 04

    Isolate heavy plugins and disable on-demand work

    Via FTP, rename `wp-content/plugins` to `plugins.disabled` (or disable the newest heavy plugins first). Retest the failing URL. Pause large imports, backups, and sync jobs while diagnosing. Deactivation by rename does not delete settings.

  5. 05

    Check database health for stuck queries

    In phpMyAdmin, host MySQL tools, or WP-CLI, look for long-running queries and locks. Kill runaway queries only if you understand the impact, then repair the plugin or report that caused them. Bloated `options`, `postmeta`, and unresolved autoload rows commonly stretch every page.

  6. 06

    Enable caching for anonymous traffic once the origin responds

    After the site can finish requests, enable page caching (host cache, plugin, or CDN) so PHP is not hit on every view. Caching does not fix a permanently hanging checkout query — it only reduces how often slow paths run.

When to stop troubleshooting

Stop if timeouts persist after plugin isolation, you cannot access slow logs or the database, workers stay saturated under normal traffic, or checkout remains 504 during revenue hours. Raising timeouts alone on an overloaded or locked database is not a repair — escalate for capacity and query remediation.

Information to collect before requesting help

  • 01 Exact URL returning 504 and whether wp-admin is affected
  • 02 Status code and CDN body (504 vs 502 vs Cloudflare 522/524)
  • 03 Host PHP slow log / error log excerpts at the failure time
  • 04 Recent plugin, traffic, CDN, or database changes
  • 05 Whether bypassing CDN changes the symptom
  • 06 Hosting provider, PHP version, and whether Redis/object cache is in use
  • 07 Whether timeouts correlate with cron, imports, or peak traffic

How a professional repairs the problem

A technician confirms the gateway layer and true status code, profiles PHP and MySQL for the hanging work, isolates heavy plugins and external calls, restores worker capacity and sane timeouts, enables caching where safe, and verifies stable TTFB on critical URLs under a light load check before returning the site to full traffic.

Frequently asked questions

Is a 504 the same as a 500? +
No. 500 usually means the app or server errored while handling the request. 504 means a gateway stopped waiting for an upstream answer — often slowness or saturation rather than an immediate fatal.
How is 504 different from Cloudflare 522? +
522 means Cloudflare could not complete a TCP connection to your origin in time. 504 (and Cloudflare 524) imply the path got further but the response still took too long or the gateway gave up waiting.
Will increasing PHP max_execution_time fix 504? +
Only if the script was legitimately near the limit and the proxy allows that long. If workers are exhausted or MySQL is locked, higher execution time can make queues worse. Fix the slow work first.
Can caching hide a 504? +
Cached anonymous pages may load while uncached URLs (cart, checkout, admin) still 504. Treat cache hits as partial relief, not proof the origin is healthy.
Why only checkout or search times out? +
Those paths run heavier queries and more plugins. Profile that URL specifically rather than optimizing the homepage alone.
Should I disable Cloudflare to fix 504? +
Use a brief grey-cloud test to locate the layer. If origin is slow, fix origin; if only the edge times out, adjust CDN timeouts and caching. Leaving the site unprotected long-term is not required once the root cause is clear.

Repair dispatch

Still Need Help Fixing Your Website?

If you are not comfortable editing website files, changing server settings, repairing a database, or troubleshooting a live website, professional help may prevent additional damage or downtime. We will review the problem before accepting the repair.

  • You will receive a clear explanation of the likely cause.
  • We will tell you if the issue falls outside our repair scope.
  • No additional work will be performed without approval.
  • A backup should be created whenever access and website condition allow it.

Do not share passwords through an unencrypted contact form.

Written by Website Rescue

Last reviewed

Platform note: Full rescue available for WordPress and self-hosted sites. Wix, Squarespace, Webflow, Weebly, and similar closed builders have very limited backend access — fixes may not be possible. I will tell you honestly before we start.