Lesson 2 of 9 · 22m
FPM Queues, Timeouts, and Backpressure
How listen queues, web-server timeouts, request timeouts, and slow upstreams interact — and how to design failure instead of discovering it.
Most PHP outages are not caused by PHP being slow. They are caused by all available workers waiting on something else while new requests pile up behind them. A database failover, Redis stall, or third-party API latency spike becomes a full-site outage because the queue silently fills and then every layer starts timing out in the wrong order.
Know the queue you are sitting on
FPM has a listen backlog in front of the workers:
listen = /run/php/php8.3-fpm.sock
listen.backlog = 511
pm.max_children = 32With a Unix socket, nginx connects to the socket and hands work to idle children. When all children are busy, connections wait in the backlog. When the backlog fills, nginx receives connection failures and starts emitting 502s. That is backpressure — ugly, visible, and usually better than infinite waiting.
Watch saturation directly:
ss -lx | grep php
cat /proc/net/unix | grep php
curl --unix-socket /run/php/php8.3-fpm.sock http://localhost/statusEnable the status page on a private listener or restricted path:
pm.status_path = /fpm-status
ping.path = /fpm-pingThe useful fields are active processes, idle processes, listen queue, and max listen queue. A nonzero listen queue over time means demand exceeds completed work, not merely that traffic exists.
Timeouts must form a ladder
fastcgi_connect_timeout 2s;
fastcgi_send_timeout 10s;
fastcgi_read_timeout 15s;request_terminate_timeout = 20scurl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 300);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1500);The web server should give up before PHP is forcibly killed, and downstream HTTP clients should give up much earlier than either. If downstream calls have no timeout, one degraded dependency can pin every worker indefinitely. That is how a 200 ms dependency turns into a site-wide 502 storm.
Shed load deliberately
For expensive endpoints, use shorter deadlines, queue nonessential work, and return controlled 503s when saturated. Backpressure is a feature when it protects the core path. A waiting-room middleware or concurrency cap is boring, but boring survives Black Friday.
Field notes
502usually means the hop to PHP failed;504usually means PHP or something behind it was too slow. They are different clues.- A growing listen queue plus high CPU means capacity. A growing queue plus low CPU means workers are blocked downstream.
- Never put the public status endpoint on the open internet; it leaks request URIs and operational detail.
- Health checks should test FPM liveness, not run the full application stack and cause cascading failures.
Was this lesson helpful?