Lesson 1 of 9 · 24m
PHP-FPM's Process Model and Why Workers Are Money
FPM capacity is a queueing problem, not a vibes problem — learn what each process manager does and how to size workers from memory and latency.
The first scaling truth in PHP is uncomfortable: every PHP-FPM worker is a mostly-blocking process that can serve one request at a time. There is no magical event loop rescuing you while a request waits on MySQL, Redis, or an upstream API. Capacity planning starts with that constraint, and most production incidents start with pretending it is not true.
What a worker actually costs
Inspect real RSS rather than trusting memory_limit:
ps -o pid,rss,cmd -C php-fpm | sort -k2 -n | tail -10
php -r 'echo memory_get_peak_usage(true), PHP_EOL;'memory_limit is a safety ceiling per request, not the resident footprint of a warm worker. Laravel, Symfony, Magento, and WordPress workers often settle between 40 MB and 150 MB after bootstrapping. If your average warm RSS is 80 MB and you reserve 2 GB for PHP on a 4 GB host, your arithmetic ceiling is roughly 25 workers, not the 100 someone copied into www.conf five years ago.
The three process managers
; /etc/php/8.3/fpm/pool.d/www.conf
pm = dynamic
pm.max_children = 24
pm.start_servers = 6
pm.min_spare_servers = 4
pm.max_spare_servers = 10
pm.max_requests = 1000statickeeps exactlypm.max_childrenalive. Predictable, lowest churn, best when PHP has a dedicated host.dynamicscales between spare bounds. Useful for shared or uneven hosts, but bad bounds cause fork storms exactly during traffic spikes.ondemandidles down toward zero. Fine for tiny internal services; usually wrong for a latency-sensitive public site.
pm.max_requests recycles workers after N requests, protecting you from slow memory leaks in application code or extensions. Do not use it as a substitute for fixing a leak; recycling 24 workers every few seconds is expensive.
Estimate instead of guessing
Measure peak RSS across several minutes of representative traffic, then calculate:
usable memory = host memory - OS - database cache - other services
max children = floor(usable memory / p85 worker RSS)Then sanity-check against CPU. A worker burning 200 ms CPU per request can serve about five requests per second per core. Twenty-four workers on four cores cannot magic away CPU saturation.
Field notes
max_childrentoo high is worse than too low: once memory pressure causes swapping, latency collapses nonlinearly.php-fpmprocess titles can lie when multiple pools exist. Check per-pool sockets and cgroup memory in containers.- In Kubernetes, set memory limits high enough for workers plus opcache, or the kernel will kill the container before PHP reaches
memory_limit. - Forking is not free. Bursty
dynamicscaling often shows up as syscall and CPU spikes before it shows up as application errors.
Was this lesson helpful?