Skip to content

PHP-FPM process manager modes: static, dynamic, ondemand

Compare PHP-FPM static, dynamic, and ondemand process manager modes and learn which mode to choose based on traffic patterns and memory constraints.

PHP-FPM’s pm directive controls whether worker processes are pre-forked and held indefinitely, grown and shrunk in response to load, or created per-request and reaped immediately. The right choice shapes your server’s memory floor, cold-start latency, and CPU burn under variable load. Choosing the wrong mode is one of the most common sources of latency spikes and OOM kills in shared and dedicated PHP environments alike.

How to verify

Inspect the current pm setting and the live worker state before changing anything:

grep -E '^pm' /etc/php/8.3/fpm/pool.d/www.conf
systemctl status php8.3-fpm --no-pager
# Check live worker counts via the status page (requires pm.status_path = /status)
curl -s 127.0.0.1/status | grep -E 'process manager|idle|active|total'
# Count running workers directly
ps aux | grep 'php-fpm: pool' | grep -v grep | awk '{print $8}' | sort | uniq -c
# Watch workers in real time
watch -n1 "ps aux | grep 'php-fpm: pool' | grep -v grep | wc -l"

After any pool change, reload without dropping connections:

systemctl reload php8.3-fpm

What’s happening

PHP-FPM ships three process manager modes. static pre-forks exactly pm.max_children workers at startup and keeps them alive regardless of demand. Every worker consumes its full memory footprint even during idle periods, but requests never wait for a worker to boot — the response curve is flat and predictable. This mode is correct for consistently busy pools where memory is available and you want zero scheduling jitter.

dynamic starts pm.start_servers workers, then grows the pool (up to pm.max_children) as idle count drops below pm.min_spare_servers, and shrinks it when idle count rises above pm.max_spare_servers. It’s the default and makes sense for servers that see moderate daytime traffic with quiet overnight windows. The downside is that the grow/shrink cycle adds latency when traffic ramps faster than FPM can fork, and the oscillation wastes CPU on servers that are busy most of the time.

ondemand starts with zero workers. A worker is forked per-request if no idle worker exists, and reaped after pm.process_idle_timeout seconds. This is the only sensible mode for pools that receive intermittent traffic (cron-triggered PHP, low-traffic staging pools, or per-site pools on a dense shared server) where keeping workers resident would exhaust RAM for no benefit. The cost is a fork-plus-opcode-cache-warmup delay on the first request after an idle window — typically 50–200 ms depending on application size.

Directive reference

Directivestaticdynamicondemand
pm.max_childrenrequiredrequiredrequired
pm.start_serversignoredrequiredignored
pm.min_spare_serversignoredrequiredignored
pm.max_spare_serversignoredrequiredignored
pm.process_idle_timeoutignoredignoredrequired
pm.max_spawn_rateignoredusedused

The procedure

1. Choose a mode based on traffic shape.

For a single-application host with steady traffic, use static:

pm = static
pm.max_children = 20

For a host with variable traffic and memory pressure, use dynamic:

pm = dynamic
pm.max_children = 20
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 10
pm.max_spawn_rate = 8

For low-traffic or intermittent pools (staging, cron, per-subdomain):

pm = ondemand
pm.max_children = 10
pm.process_idle_timeout = 30s

2. Set pm.max_children from measured memory, not intuition. Sample the resident set of running workers:

ps aux | grep 'php-fpm: pool www' | grep -v grep | awk '{print $6}' | sort -n | tail -5

Divide usable RAM by the 90th-percentile worker RSS. Reserve headroom for the OS, MySQL, Nginx, and system caches. A typical Symfony or Laravel worker at 128 MiB yields 8–12 children on a 2 GiB node.

3. Reload, not restart. systemctl reload php8.3-fpm sends SIGUSR2 to the master. It re-reads php-fpm.conf and gracefully replaces workers without rejecting in-flight connections. A full restart causes a brief gap where the socket disappears.

4. Monitor after the change. Watch the status page for listen queue values greater than 0 — a non-empty queue means workers are saturated. If you see queue depth growing, increase pm.max_children or move to static to eliminate the fork delay under burst.

watch -n2 "curl -s 127.0.0.1/status?full | grep -E 'listen queue|active|idle'"

Common pitfalls

Setting pm = dynamic on a perpetually busy pool. If active workers never drop below pm.min_spare_servers, FPM permanently oscillates: it forks workers only to reap them moments later. Use static and fix the value.

Using pm.start_servers greater than pm.max_children. PHP-FPM silently clamps start_servers to max_children but logs nothing obvious. The result is confusing ps output where worker counts never exceed the capped value.

Ignoring pm.max_spawn_rate during traffic spikes. This directive (default 32 in PHP 8.x) caps how many new workers FPM will fork per second. If your application sees sharp bursts, raise it to avoid queuing during the ramp-up window.

Leaking file descriptors with ondemand at high throughput. Every forked worker inherits all open file descriptors from the master. If your master has a large rlimit_files, validate that the OS-level limit (fs.file-max on Linux) accommodates max_children workers each with their own open FDs.

Not setting pm.max_requests. Regardless of mode, set pm.max_requests = 500 (or similar) to periodically recycle workers and shed long-lived memory growth from extensions that accumulate state across requests.

For sustained PHP-FPM management under load — including pool configuration review, memory profiling, and incident response — the Stack Harbor managed operations service provides on-demand expertise.