Skip to main content

Site Errors

How to Fix a 504 Gateway Timeout: Finding the Process That Ran Too Long

A 504 means one server in the request chain waited on another and gave up, so fixing it means finding which process - PHP, a plugin, or a query - ran past its allowed time and shortening it.

30-60s

Typical default before a gateway gives up and returns 504

NVMe SSD

Storage that cuts disk-read wait time behind slow queries

LiteSpeed

Web server tech used to process requests faster

24/7

Human support available to help trace a 504's source

In short

How to fix 504 gateway timeout starts with understanding it's a timing failure, not a crash: an upstream process (a PHP script, database query, or plugin task) took longer than the server's configured wait limit, so the connection was dropped before a response came back. Fixing it means finding that slow process and either speeding it up or raising the relevant timeout setting.

A 504 gateway timeout looks like a dead site, but it's actually a very specific kind of failure: the server in front of your site (often a reverse proxy or load balancer) sent a request to the server actually running your code, waited the amount of time it's configured to wait, and got nothing back in time. It then gave up and returned a 504 rather than hang indefinitely, which is why the error often appears and disappears depending on what a page happens to be doing at that moment.

That intermittent quality is the biggest clue when diagnosing a 504. A page that always times out points to something structurally slow - a runaway database query or a plugin doing heavy work on every load. A page that times out only sometimes points to load spikes, a script hitting an external API that's slow to respond, or a cron job competing for resources at the same moment a visitor requests the page.

Why a 504 is different from a 500 or 502 error

A 500 error means the code itself crashed - a fatal PHP error, a missing file, a broken function call. A 502 means an upstream server sent back an invalid or garbled response. A 504 means neither of those happened; the process was still running, just too slowly, and the gateway timed it out before it could finish and reply. That distinction matters because a 504 fix isn't about repairing broken code, it's about finding what's taking too long and either speeding it up or giving it more time to finish.

This is also why a 504 so often correlates with specific actions rather than the whole site: a checkout page calling a payment gateway, a WordPress admin screen regenerating thumbnails for a large media library, or a report page running an unindexed database query across thousands of rows. General homepage loads stay fast while one specific heavy page keeps timing out, which is usually the fastest way to narrow down the cause.

Checking PHP execution time and memory limits

PHP's max_execution_time setting caps how long a script is allowed to run before PHP itself kills it, and if that cap is lower than the gateway's timeout, PHP will actually error out first with a different message - but if it's set too high, PHP keeps working past the point the gateway has already given up, producing the 504 a visitor sees. In cPanel, this is adjusted under the PHP Selector or MultiPHP INI Editor, where max_execution_time, max_input_time, and memory_limit can all be raised for scripts that legitimately need more processing time.

Before raising the limit, it's worth checking why a script needs more time in the first place. A contact form that times out on submit might be waiting on a slow outbound email connection; an import script might be looping through rows one at a time instead of in batches. Raising the execution time limit treats the symptom, while fixing the underlying loop or query removes the timeout risk for good instead of just pushing the ceiling higher.

Finding the plugin or query causing the delay

On a WordPress site, the most common 504 source is a plugin doing synchronous work during a page load - regenerating a sitemap, resizing images, or calling an external API that itself is slow to respond. Deactivating plugins one at a time (starting with anything related to SEO, backups, image optimization, or security scanning, since those tend to run the heaviest background tasks) and reloading the affected page usually isolates the culprit quickly.

If deactivating plugins doesn't resolve it, the next place to look is the database. A query without a proper index can take seconds on a table that used to return in milliseconds, especially as an orders, posts, or logs table grows over time. Slow query logs or plugin-level query monitors can surface the exact query responsible, and adding an index or rewriting the query to filter more efficiently usually removes the delay at its source.

When the fix is server-side, not code-side

Sometimes the code is fine and the issue is genuinely a resource ceiling being hit - a shared-tier account under heavy simultaneous load, or a task that's simply resource-intensive by nature, like a large export or a bulk media import. In those cases the fix is either scheduling the heavy task for a quieter time, breaking it into smaller batches, or moving to a plan with more dedicated resources rather than continuing to fight the same timeout.

This is where infrastructure matters: NVMe SSD storage and LiteSpeed's request handling reduce how long typical read and write operations take in the first place, which lowers the odds any given script bumps against a timeout under normal conditions. If a 504 keeps recurring despite code-level fixes, Hosting Cheap's 24/7 human support can check server-side logs and timeout configurations directly rather than leaving the diagnosis to guesswork alone.

How to Fix a 504 Gateway Timeout Error on Your Site

Diagnose 504s faster with support that can see the server side

A 504 gateway timeout often needs a look at both the code and the server configuration behind it, and Hosting Cheap's 24/7 human support can check timeout settings and server logs directly instead of leaving the whole diagnosis to trial and error.

NVMe SSD storage and LiteSpeed request handling keep everyday read and write operations fast, reducing how often normal-sized tasks come anywhere near a timeout ceiling in the first place.

  • 24/7 human support to check server-side timeout logs directly
  • NVMe SSD + LiteSpeed to keep queries and page loads fast
  • cPanel-style PHP settings to adjust execution time limits
  • Free managed migration if a move to more resources is needed

Why Hosting Cheap

What you get

Fast underlying storage

NVMe SSD reduces disk read and write wait time, lowering the chance a normal task bumps into a timeout ceiling.

LiteSpeed request handling

LiteSpeed processes requests more efficiently than older server software, shortening typical response times.

Adjustable PHP limits

cPanel-style PHP Selector settings let execution time and memory limits be raised for scripts that need it.

24/7 human support

Support can check server-side logs and timeout configurations directly when a 504 keeps recurring.

Free managed migration

If a site has genuinely outgrown shared-tier resources, migration to a higher tier is handled at no cost.

30-day money-back guarantee

Test a plan against real timeout-prone pages with a full 30 days to confirm the fix holds.

How It Works

Get set up in a few steps

1

Identify which page or action triggers the 504

Note whether it's constant on one page or intermittent site-wide, since that narrows the likely cause.

2

Isolate the slow process

Deactivate plugins one at a time or check slow query logs to find the specific script or query responsible.

3

Fix the source or adjust the limit

Optimize the slow query or plugin task, or raise max_execution_time in cPanel's PHP settings if the task legitimately needs more time.

Included

Everything you need, on every plan

  • Confirm whether the 504 happens on one specific page or across the whole site
  • Check cPanel's PHP Selector for current max_execution_time and memory_limit values
  • Deactivate plugins one at a time to isolate a heavy background task
  • Check slow query logs for an unindexed database query
  • Review any code that calls a slow external API during page load
  • Schedule heavy import or export tasks for low-traffic periods
  • Contact 24/7 human support if the timeout persists after code-level checks
  • Re-test the affected page after each change to confirm the fix worked

FAQ

Frequently asked questions

What does a 504 gateway timeout actually mean?

It means an upstream server sent a request to the server running your code and didn't get a response back within the configured wait time, so the connection was dropped and a 504 was returned instead of hanging indefinitely.

Is a 504 error caused by my code or the server?

It can be either - a slow plugin task or unindexed database query is a code-side cause, while a resource ceiling under heavy load is a server-side cause. Isolating which page triggers it usually points to which one applies.

How do I raise the PHP execution time limit?

In cPanel, the PHP Selector or MultiPHP INI Editor lets you adjust max_execution_time, max_input_time, and memory_limit for the PHP version your site uses.

Why does a 504 happen only sometimes, not every time?

Intermittent 504s usually point to load-dependent causes, like a cron job running at the same time as a visitor request, or an external API that's occasionally slow to respond rather than a fixed structural delay.

Can a plugin really cause a 504 gateway timeout?

Yes, plugins that do synchronous work during page load - image resizing, sitemap generation, or external API calls - are one of the most common causes on WordPress sites, and deactivating them one at a time usually isolates it.

Does upgrading hosting fix a 504 error?

It can if the cause is genuinely a resource ceiling, since more dedicated resources reduce contention under load. But if the cause is a slow plugin or unindexed query, fixing that directly resolves it without needing to upgrade at all.

Still seeing 504 gateway timeout errors?

Talk to 24/7 human support to check server-side timeout logs, or move your site onto NVMe SSD and LiteSpeed infrastructure with free managed migration.

Get Started