Prevent PHP-FPM ondemand Requests from Stalling in the Backlog

A PHP-FPM ondemand pool can appear idle while a request remains queued on its listening socket. First confirm that the socket has a backlog entry and no pool child is running. Then use a dynamic pool for latency-sensitive traffic or lengthen the idle timeout while the reported race is investigated.

Last updated: November 17, 2026.

[app]
listen = /run/php/app.sock
listen.backlog = 511

pm = dynamic
pm.max_children = 12
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 4

pm.status_path = /fpm-status
pm.status_listen = /run/php/app-status.sock

Size the child limits from measured memory and concurrency. A dynamic pool keeps spare workers available, so it uses more baseline memory than ondemand.

Confirm the failure before changing the pool

A current PHP source issue reports a timing window where a connection arrives while the master is terminating the last idle child. The request remains in the Unix-socket backlog until another connection wakes the pool. The report reproduces the behavior across multiple PHP-FPM versions, but it is still a version-specific open issue rather than proof that every stalled request has this cause.

During an incident, capture the PHP version, pool mode, idle timeout, master and child processes, socket queue state, FPM log and upstream timeout. A full pm.max_children pool, slow PHP request, permissions error or unavailable upstream needs a different fix.

Choose a bounded mitigation

The PHP-FPM configuration reference explains that ondemand starts children when requests arrive and removes idle children after pm.process_idle_timeout. Increasing that timeout reduces worker churn but does not prove the race is eliminated. Switching the affected pool to dynamic avoids the last-idle-child transition at the cost of resident workers. Increasing listen.backlog alone does not create a child to consume an already queued request.

Keep upstream FastCGI timeouts finite so one stuck request cannot wait forever. Expose the FPM status endpoint only through a protected local path, and monitor active, idle and queued connections. Re-test with the same low request rate that triggered the issue, then follow the upstream report and PHP release notes before removing the mitigation.

Related Web Cheat Sheet guides

Sergey Kornilov

Sergey Kornilov