Skip to content
HTTP status codes3 min read

504 Gateway Timeout: the response didn't arrive in time

504 Gateway Timeout

Short answer

A 504 Gateway Timeout means a gateway or proxy, such as Cloudflare or the web server, passed the request to the server or app behind it and waited, but no response arrived before the timeout. It's usually a slow script, a heavy database query, or an external API call that never answers.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. What causes a 504 error
  2. Fixing it as a visitor
  3. Fixing it as the site owner
  4. Prevention
  5. On ArabyHost

Every gateway waits a fixed time for a reply and then gives up. When that time runs out, it answers the browser with 504 Gateway Timeout. Unlike a 502, the backend usually didn’t crash; it was too slow or stuck waiting on something else. So focus your fix on the specific slow page or job.

What causes a 504 error

  • A slow PHP script: a huge report, importing thousands of products, or creating a backup from the browser.
  • Slow database queries: large tables without indexes, or tables locked by another process.
  • An external API that doesn’t answer: a payment gateway, shipping company or AI service, with code that waits forever.
  • Resource limits: when the account hits its CPU limit, processes slow down and miss the timeout.
  • wp-cron and heavy tasks running on visitor requests.
  • A gateway timeout shorter than the script’s runtime, even with a large max_execution_time.

Fixing it as a visitor

Wait a moment and retry. If you were paying for something, don’t repeat it immediately: check your email or your account on the site first, because the order may have gone through despite the error.

Fixing it as the site owner

  1. Find the slow page: does it happen everywhere or on one page or action? Check Metrics → Raw Access and Metrics → Errors in cPanel around the time of the error.
  2. Time it yourself: measure the page’s time to first byte (TTFB):
curl -o /dev/null -s -w "TTFB: %{time_starttransfer}s\n" https://example.com/page
  1. Find the culprit in WordPress: install the Query Monitor plugin temporarily to see the slowest queries and plugins on the page.
  2. Put a timeout on every outbound request so the script can’t hang:
$response = wp_remote_get( $url, array( 'timeout' => 10 ) );

With cURL, use CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT.

  1. Move long jobs to the background: run imports and reports from a cron job under Advanced → Cron Jobs, a Laravel queue, or WP-CLI over SSH, and process them in small batches.
  2. Review PHP limits: in Software → Select PHP Version → Options you can raise max_execution_time for jobs that need it. If you see “Maximum execution time exceeded”, see that error.
  3. Tune the database: add indexes on columns you search by, and clean up large tables such as plugin logs.
  4. Turn on caching so heavy pages aren’t rebuilt on every visit.

If the site is behind Cloudflare and the error number is 524, see Cloudflare error 524.

Prevention

  • Never make a web request depend on a long job; respond quickly and do the work in the background.
  • Set a short timeout on every outbound connection, with a clear message for the user when it fails.
  • Review your slowest pages regularly, especially after adding plugins.

On ArabyHost

Sites run on LiteSpeed, and you set PHP limits yourself in Select PHP Version in cPanel. AI/Developer plans add SSH and cron so long jobs and background workers run outside web requests. Each account has its own CloudLinux LVE limits, and the Resource Usage page shows whether slowness lines up with those limits. The Araby AI assistant can read your error log and point to the slow process.

FAQ

Will raising max_execution_time fix a 504?

Often not. It lets PHP run longer, but the gateway in front has its own timeout that may be shorter. The better fix is making the work faster or moving it into a background job.

I only get 504 when importing products or running a backup. Why?

Those are long jobs running inside a single web request. Split them into small batches, or run them with cron or WP-CLI instead of the browser.

What's the difference between 504 and Cloudflare error 524?

Both are timeouts. A 524 is Cloudflare-specific and means it connected to your server fine but waited too long for the response. A 504 can come from any gateway, including the web server itself.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.