Skip to content

5xx Server errors

504 Gateway Timeout

A proxy waited too long for the server behind it. The request may still finish on the server.

Common causes

  • A slow request: a large report, an external API that hangs, a slow database query.
  • A proxy timeout (Cloudflare: about 100 seconds) shorter than the request.

How to fix a 504 error

  1. 1

    Move long work to a queue job and show progress instead of waiting.

  2. 2

    Add timeouts to external HTTP calls (Http::timeout(10)).

  3. 3

    Find slow queries with the query log or EXPLAIN and add indexes.

In Laravel

Http::timeout(10)->retry(2, 200)->get($url) keeps a hanging API from holding the request.

Check the status of a URL

The first line of the response shows the status code; -L follows redirects and shows each step.

curl -I https://example.com/page
curl -IL https://example.com/old-page

Frequently asked questions

What does HTTP 504 mean?

A proxy waited too long for the server behind it. The request may still finish on the server.

How do I fix a 504 error?

Move long work to a queue job and show progress instead of waiting. Add timeouts to external HTTP calls (Http::timeout(10)). Find slow queries with the query log or EXPLAIN and add indexes.

How does Laravel handle 504?

Http::timeout(10)->retry(2, 200)->get($url) keeps a hanging API from holding the request.

Get new articles in your inbox

Practical tutorials and deep dives, about once a week. No spam, unsubscribe anytime.

Privacy policy

Add DEV Talk to your Home Screen

  1. 1 Tap the Share button in Safari's toolbar.
  2. 2 Scroll down and tap Add to Home Screen.
  3. 3 Tap Add. Open it from the Home Screen to read like an app and to turn on notifications with the bell.

We use cookies to improve your experience and analyze traffic. By continuing, you agree to our Privacy Policy.