Cloudflare error 524: a timeout occurred

Your server took longer than Cloudflare's 100-second limit to respond. Find the slow part and move long tasks to background jobs.

· 3 min read · By the Spot Downtime team

Error 524: A timeout occurred means Cloudflare connected to your server just fine, sent the request, and then waited too long for an answer. By default, Cloudflare waits 100 seconds for a proxied request. If your server hasn't started responding by then, the visitor gets a 524.

Your server is up. Something in it is slow, or the request is doing too much work for a single HTTP request.

Common causes

Long-running work in a request

Exports, report generation, image processing, bulk imports, or an admin action that loops over every record. These are fine with a hundred rows and time out with a hundred thousand.

A slow database query

A query on a table that grew, missing an index, or waiting on a lock held by another transaction. Check the database's slow query log around the time of the 524s.

A call to another service that hangs

Your code calls a payment provider or an internal API without a timeout. When that service is slow, your request waits as long as it does. Always set timeouts on outbound calls, well under 100 seconds.

Overloaded workers

All PHP-FPM or app workers are busy, so new requests queue. Each one is quick, but the wait in the queue pushes it past the limit.

How to fix it

  • Move long tasks to a background job. Accept the request, queue the work, return 202 Accepted and let the user poll or get notified when it's done.
  • Find the slow part. Your app's logs or APM show which endpoint and which query took the time.
  • Bypass the proxy for genuinely long admin tasks, using a DNS-only (grey cloud) subdomain, if you can't move them to a background job yet.
bash
# time a request directly at the origin, bypassing Cloudflare
curl -o /dev/null -s -w "ttfb: %{time_starttransfer}s\n" \
  --resolve example.com:443:203.0.113.10 https://example.com/slow-page
Website speed testSee how long a page takes to start responding (time to first byte), and every step before it.

Slow comes before down

Pages rarely jump from 1 second to 100. They creep up as data grows. Watching response times on a monitor shows the trend weeks before the first 524, while it's still a quiet fix instead of an outage.

Without Cloudflare, the same problem appears as a 504 Gateway Timeout from your own proxy.

Keep reading