php5-fpm: server reached pm.max_children

Solution 1:

There are many possible reasons why your PHP-FPM would reach the max_children. Most common ones are:

  • A lot of parallel requests from your clients
  • Slow execution of the PHP scripts
  • Very low setting of the max_children

Looking at the specs of your machine, assuming there is nothing else than PHP+Nginx running, I think you could set it much higher than 5. You say you have 8 Cores, usually Nginx needs much less CPU than PHP, so with 5 children you will probably never be able to use all of them. I'm usually setting it to something like the number of cores x 2 or number of cores x 4, depending on the memory consumption of your PHP scripts.

Solution 2:

I found that by setting the pm.max_requests value (which is commented out by default) helped in fixing these errors. This setting forces child requests to respawn after executing a certain number of requests and can be helpful if there are memory leaks somewhere in your code or 3rd party libs.

In /etc/php-fpm.d/www.conf:

pm.max_requests = 500


Php Fpm