Skip to content

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

Key points

  • Calculate workers from memory, do not guess.
  • The slow log shows which script and line.
  • More workers on a saturated database make things worse.
  • pm.status_path gives live pool numbers.

What it means

php-fpm has a pool of worker processes and each handles one request. Once pm.max_children are busy, requests wait in the listen queue. Eventually Nginx gives up with a 502 or a 504.

Common causes

  • Slow requests that hold workers, generally database or remote calls.
  • A pool sized too small for traffic.
  • A traffic spike or bots, such as xmlrpc.php attacks on WordPress.
  • Locking sessions, where parallel requests from one user queue up.

Diagnose it

Measure average worker memory and see which scripts are slow.

bash
# 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.log

Fixes

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.

Frequently asked questions

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

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.