'Server reached pm.max_children': sizing PHP-FPM properly
Short answer: PHP-FPM runs a pool of worker processes, and pm.max_children is the maximum number of requests it will handle at once. When every worker is busy, new requests queue, pages stall, and the log says "server reached pm.max_children setting". Raising the number helps only if the server has memory for more workers; otherwise it swaps and gets slower. Find out why workers are busy (slow pages, uncached traffic, bots, slow external calls), size the pool to your memory, and use FPM's status page and slow log to see what's going on.
What the warning means
PHP's documentation describes pm.max_children as the setting that limits the number of simultaneous requests served: the fixed number of processes when the process manager is static, and the maximum when it's dynamic or ondemand. When all those processes are busy, further requests wait in a queue until a worker is free.
The warning isn't an error in itself. Short spikes that briefly hit the limit can be harmless. Repeated warnings plus slow pages mean demand regularly exceeds what the pool can handle.
Step 1: see the pool in action
PHP-FPM has a built-in status page, enabled with pm.status_path. PHP's documentation lists what it reports, including:
- listen queue: requests currently waiting for a free process
- max listen queue: the most that have waited at once
- active and idle processes
- max children reached: whether the limit has ever been hit
- slow requests: requests that exceeded the slow log threshold
- memory peak
Expose it only to localhost or your monitoring, never publicly. If the listen queue regularly climbs and max children reached keeps counting, the pool really is saturated.
Step 2: find why workers are busy
More workers is only one answer. Often the better question is why each request takes so long or why there are so many:
- Slow pages. PHP's
request_slowlog_timeoutwrites a PHP backtrace to the slow log for any request that takes longer than the threshold. Set it to a few seconds and you'll see which code is slow: a plugin, a database query, an external API call. - No page caching. For WordPress and similar sites, every anonymous visitor hitting PHP is wasteful. Full-page caching serves most visitors without touching PHP-FPM.
- Bots and crawlers. Aggressive crawlers, login attacks or search pages being hammered can occupy workers. Check your access log for the busiest IPs and URLs.
- Slow external calls. A payment, shipping or stock API that hangs ties up a worker for the whole wait. Set timeouts.
- Background work in requests. WordPress's built-in cron or heavy admin tasks running during page loads.
Fixing these reduces how many workers you need.
Step 3: size the pool to your memory
Each worker uses memory, and a busy WordPress or Laravel worker can use far more than an idle one. A practical way to size:
- Under normal load, measure the memory used by PHP-FPM worker processes, and note the typical size of a busy one.
- Subtract what the server needs for everything else: database, web server, cache, operating system.
- Divide the remainder by the per-worker size. That's the ceiling for
pm.max_children.
Setting it higher than memory allows leads to swapping or the system killing processes, which is worse than queueing.
Choosing pm mode
PHP's docs describe three modes:
- static: a fixed number of workers, always running. Predictable; good for dedicated servers.
- dynamic: starts some workers and adjusts between minimum and maximum spare settings, up to the max.
- ondemand: starts workers only when requests arrive, and kills idle ones after
pm.process_idle_timeout. Saves memory on quiet sites with several pools, but adds a little start-up delay.
For a small VPS hosting one busy site, dynamic or static is usual.
Two settings worth adding
pm.max_requests: PHP's docs describe this as the number of requests each worker handles before being replaced, useful to work around memory leaks in third-party libraries. A value in the hundreds keeps slow memory growth in check.request_terminate_timeout: kills a worker serving a single request for too long, for cases where PHP's own execution time limit doesn't stop it. It prevents a few runaway requests from occupying the pool indefinitely.
Several sites on one server
If the server hosts several sites, give each its own pool with its own user and limits. Then a traffic spike or a misbehaving plugin on one site fills only that site's pool instead of starving the others. The total of all pools' maximums still has to fit in memory, so share it out according to each site's real traffic rather than giving every pool the same number.
How it relates to 502 and 504 errors
If requests wait in the queue longer than the web server's timeout, visitors get a 504. If workers crash or the queue is full, you may see 502s. Fixing pool saturation often clears both.
A worked example
An illustrative Sacramento garden supply store on WooCommerce slowed to a crawl every Saturday morning. The PHP-FPM log showed "server reached pm.max_children" and the status page showed a long listen queue. The slow log pointed to a stock-sync plugin calling a supplier API on product page views. They moved the sync to a scheduled job, enabled page caching for anonymous visitors, measured per-worker memory and set pm.max_children to what the server could hold, plus pm.max_requests to recycle workers. Saturday traffic now stays well under the limit.
FAQ
Should I just double pm.max_children?
Only if you have the memory. Otherwise you'll trade queueing for swapping.
Does more CPU help?
If workers are busy computing, yes; if they're waiting on databases or APIs, fix the waits first.
Where are the logs?
Check your PHP-FPM pool configuration for the error log and slowlog paths.
Does this apply to shared hosting?
You usually can't change it there; ask your host or move to a plan where you can.
If your PHP site stalls under load, send us your PHP-FPM settings and a slow log and we'll help you find the bottleneck.