PHP-FPM runs a fixed number of worker processes. Each request needs a free worker. When all of them are busy, new requests wait in a queue, pages hang, and eventually the web server returns 502 or 504 errors.

What it looks like

  • Pages load very slowly or time out, often at busy times.
  • Nginx returns 502 Bad Gateway or 504 Gateway Timeout.
  • The PHP-FPM log shows “server reached pm.max_children setting (N), consider raising it”.

Confirm it

grep -i "max_children" /var/log/php8.2-fpm.log | tail
ps -C php-fpm8.2 --no-headers | wc -l

Adjust the version to match your server.

Do not just raise max_children

The log suggests raising the limit, but that is often the wrong fix. Workers pile up because each one is held too long. Usually it is waiting on a slow database query, a locked table, or a slow external API such as a shipping rate or payment check. More workers on the same CPU and memory just compete harder and can make it worse.

Find what the workers are waiting on

  • Database: run SHOW FULL PROCESSLIST; in MySQL during the slowdown. Long-running or locked queries are the most common cause.
  • Slow log: enable the PHP-FPM slow log in your pool config to see which code each slow request was running:
    request_slowlog_timeout = 10s
    slowlog = /var/log/php-fpm-slow.log
  • External calls: extensions calling outside APIs without a timeout can hold a worker for minutes.

Protect the store meanwhile

Add a hard limit so no single request can hold a worker forever:

request_terminate_timeout = 60

Restarting PHP-FPM frees stuck workers immediately and buys time, but it does not fix the cause. Make sure full page cache works, because cached pages never reach PHP at all.

When raising the limit is right

If workers are genuinely busy doing useful work and the server still has spare memory, raise pm.max_children. A safe estimate is available memory divided by the average memory per PHP-FPM process.

Catch it automatically

MageMonitor checks for this every few minutes as part of its server checks, and alerts you by email, Slack or webhook the moment it appears, with the exact commands to fix it. See MageMonitor for Magento 2.

Related fixes