The site suddenly stops responding, CPU is at 100%. Nginx throws a 502 error. You check the log: server reached pm.max_children. Random blogs tell you to "just set it to 500." Do that, and your server will drop into swap and lock up completely. You'll have to hard reset.

The Fix: You can't just guess that number. You have to find the server's free RAM and divide it by the RAM a single PHP process consumes. Use ondemand instead of dynamic.

  1. Find out how much RAM one PHP process uses on average:

Bash
 
ps -ylC php-fpm --sort:rss | awk '{sum+=$8; ++n} END {print "Avg: " (sum/n)/1024 " MB"}'
  1. Let's say it's 50 MB. If you have 2000 MB of free RAM available for PHP: 2000 / 50 = 40.

  2. Open the pool config: nano /etc/php/8.1/fpm/pool.d/www.conf

  3. Change the values based on your math:

Ini, TOML
 
pm = ondemand
pm.max_children = 40
pm.process_idle_timeout = 10s
pm.max_requests = 500
  1. Restart the service: systemctl restart php8.1-fpm

Memory bloat stops, and zombie processes won't drain your server anymore.

🤔

Was this answer helpful?

Görüşünüz bizim için değerli!