Troubleshooting guide
php-fpm "server reached pm.max_children": how to fix it
All PHP workers are busy and new requests are queueing. The fix is either more workers, if memory allows, or faster requests, which is usually the real answer.
3 min read11 sectionsUpdated
On this page
# How often has the limit been hit?
sudo grep -c 'max_children' /var/log/php*-fpm.log
# Average worker memory in MB
ps --no-headers -o rss -C php-fpm8.2 | awk '{s+=$1} END {print s/NR/1024 " MB"}'
# Enable in the pool config, then reload:
# pm.status_path = /fpm-status
# request_slowlog_timeout = 3s
# slowlog = /var/log/php-fpm-slow.log
sudo tail -40 /var/log/php-fpm-slow.logFixes
Calculate the ceiling: (RAM available for PHP) / (average worker MB). With 6 GB and 60 MB workers, pm.max_children can be about 100. Exceeding memory causes swapping and worse outcomes. Use pm = dynamic for most sites, ondemand for low-traffic pools and static for predictable heavy traffic. Then fix the slow scripts the log points to. Add OPcache and a page or object cache for anything that does not need to be rendered per request.
Why more workers may not help
If each worker is waiting on a database that is already saturated, adding workers adds more concurrent queries to that same database, and everything becomes slower. Check whether workers are busy on CPU or merely waiting. The slow log's stack trace gives the answer: frames in mysqli_query or curl_exec show where the wait occurs. If the same URL dominates, look for abuse, too. Blocking unwanted bot traffic at the edge often recovers more capacity than tuning ever will.
Catch it automatically
Poll /fpm-status for listen queue and active processes near the limit and chart them in infrastructure monitoring. APM shows which endpoint holds workers. For a CMS, see WordPress monitoring.
How high should pm.max_children be?
As high as memory allows, based on average worker size. Leave room for the database and the OS.
Which is better, static or dynamic?
Static suits steady high traffic. Dynamic suits most sites with varying load.
Why do I get a 502?
Requests waited too long in the queue, or the listen backlog overflowed.
Check it now, free
- Response time checker: Measure TTFB with DNS, connect, TLS and server time.
Related reading
- Apache "server reached MaxRequestWorkers": how to fix it: Fix Apache server reached MaxRequestWorkers setting: choose the right MPM, calculate workers from memory and move away from mod_php for better concurrency.
- PHP maximum execution time exceeded: how to fix it: Fix PHP Maximum execution time of 30 seconds exceeded: why external waits may not count, which timeouts line up with Nginx, and how to move long work away.
- Redis "max number of clients reached": how to fix it: Fix Redis ERR max number of clients reached: find leaking applications with CLIENT LIST, tune maxclients and file limits, and pool or multiplex connections.
- JavaScript heap out of memory: how to fix it in Node.js: Fix FATAL ERROR: JavaScript heap out of memory. Set --max-old-space-size correctly, handle build-time failures and find runtime leaks with heap snapshots.
- MySQL server has gone away: causes and how to fix it: Fix MySQL error 2006 server has gone away: idle timeouts, oversized packets, server restarts and connection pools holding connections that have died.
- Cloudflare error 521: web server is down: Fix Cloudflare error 521 "Web server is down": the origin refused the connection. Check the web server, firewall rules for Cloudflare IPs and DNS.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.