max_children warning, and cranks the number up — from 10 to 50, maybe 100. More workers, more requests handled simultaneously, faster site. Sounds logical. Except on a server with limited RAM, this is exactly how you turn intermittent slowness into a hard outage.
Why more workers does not mean more capacity
pm.max_children seems like the obvious fix: more workers, shorter queue, fewer errors. The part people miss is that each worker is a separate process that consumes real memory. A bare PHP process might use 20-30 MB. Load WordPress with WooCommerce, a page builder, and a handful of plugins, and each worker can easily consume 60-80 MB or more.
Do the math on a 2 GB VPS. The OS and services (MySQL, web server, mail) typically need 600-800 MB. That leaves roughly 1.2 GB for PHP-FPM. If each worker uses 60 MB, you can fit about 20 workers before RAM runs out. Set max_children to 50 and you are asking for 3 GB of PHP-FPM memory on a box that has 2 GB total.
What happens next: the Linux kernel's OOM (Out of Memory) killer starts terminating processes. Sometimes it kills a PHP-FPM worker. Sometimes it kills MySQL. Sometimes it kills the master PHP-FPM process itself. The result is not a slow site — it is a dead one. Every request returns 502 or 503 until someone restarts services or the box reboots.
How to measure what each worker actually uses
BASH
ps --no-headers -o rss -C php-fpm | awk '{ sum += $1; n++ } END { print "Workers: " n; print "Avg RSS (KB): " sum/n; print "Avg RSS (MB): " sum/n/1024 }'TEXT
Workers: 12
Avg RSS (KB): 61440
Avg RSS (MB): 60The formula for max_children
free -m. Look at the "available" column — that is what the kernel considers actually free for new allocations. But do not give all of it to PHP-FPM. Leave a buffer (at least 10-15% of total RAM) so the OS has room for disk cache and spikes.
Illustrative example on a 4 GB VPS:
- Total RAM: 4096 MB
- OS + MySQL + web server: ~1200 MB
- Safety buffer (~15%): ~600 MB
- Available for PHP-FPM: ~2300 MB
- Average worker RSS: 60 MB
- max_children: 2300 / 60 ≈ 38
max_children to 38 keeps the server within its memory budget. Setting it to 100 would request 6000 MB of PHP-FPM memory alone — guaranteed OOM.
Choosing the right process manager mode
pm directive in your pool config controls how PHP-FPM spawns and manages workers. The pool config file is typically at /etc/php/<version>/fpm/pool.d/www.conf on Debian/Ubuntu systems, though the path varies by distro and PHP version.
Three modes exist:
pm = static — Spawns exactly pm.max_children workers at startup. They stay alive permanently. No spawn/kill overhead per request. Best when the server is dedicated to PHP and you want predictable memory usage. Downside: those workers consume RAM even when idle at 3 AM.
pm = dynamic — Starts with pm.start_servers workers, scales up to pm.max_children under load, and kills idle workers down to pm.min_spare_servers. Most common default. Good for servers that handle variable traffic. The key settings:
INI
pm = dynamic
pm.max_children = 38
pm.start_servers = 8
pm.min_spare_servers = 4
pm.max_spare_servers = 12pm = ondemand — No workers running when idle. Spawns a worker only when a request arrives, kills it after pm.process_idle_timeout seconds of inactivity. Lowest memory usage at rest. Downside: first request after idle pays a spawn penalty (typically tens of milliseconds). Useful on servers hosting many low-traffic sites where you cannot afford idle workers for each pool.
For most single-site VPS setups, dynamic works well. The critical part is not which mode you pick — it is that pm.max_children stays within your RAM budget regardless of mode.
What the logs tell you when it goes wrong
TEXT
WARNING: [pool www] server reached pm.max_children setting (38), consider raising this valuemax_children makes things worse. The correct response is to figure out why all workers are busy:
- Slow database queries holding workers longer than necessary
- External API calls blocking workers for seconds
- Missing OPcache causing PHP to recompile scripts on every request
- A stuck or runaway PHP process occupying a worker indefinitely
max_children warning alongside 502 errors specifically, Reading PHP-FPM Logs to Confirm max_children Is Causing Your 502 Errors walks through the log analysis step by step.
When you genuinely need more workers
max_children safely.
Another option: reduce per-worker memory. Enable and properly size OPcache so compiled scripts are stored in shared memory instead of being loaded per-worker. Audit plugins and extensions that bloat memory. Switch from mod_php to PHP-FPM if you have not already (though if you are reading this, you probably have).
The short version
pm.max_children is not a performance knob you turn up for speed. It is a capacity limit that must stay within your server's RAM budget. Measure actual worker memory under real traffic, subtract what the OS and other services need, divide, and set the value accordingly. If all workers are busy, investigate why requests are slow before adding more workers. More workers on insufficient RAM does not produce a faster site — it produces 503s and OOM kills.