How To: Solve PHP-FPM server reached max_children

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

  • A lot of concurrent site visitors
  • Slow execution of the PHP scripts due to server resources or buggy scripts
  • Very low setting of max_children setting in php-fpm config

If you have a busy server your php-fpm may crash out with the following error in the logs ( /var/log/phpX-fpm.log or /var/log/plesk-phpXX-fpm/error.log , where X is a PHP version):

Look for the following entries:

Your website is not accessible with 503 Service Temporarily Unavailable or 502 Bad Gateway error.

Check that php-fpm service is running:

Expected output should be running (once):

Check number of allowed running php-fpm processes

Expected output:

Resolution: Edit the conf file with the following:

or

For Plesk follow the instructions on the header of the conf file to override default php-fpm values by creating a custom php.ini file with specific fpm directives in:

Note that if the file is non-existent and you may need to create it.

Add the following entries:

Or for Plesk optionally just add the following entries:

Restart php-fpm service:

For Plesk you need to update PHP settings to apply the changes:

If that fails you can try to recompile domains settings:

or for one domain:

Then restart php-fpm56 service (or php-fpmXX where X is a PHP version used in Plesk):

Verify the max_children limit has increased using the above commands.

If you need to calculate and change these values based on the amount of memory on the system the following command will help us to determine the memory used by each (PHP-FPM) child process:

The RSS column shows non-swapped physical memory usage by PHP-FPM processes in kilo Bytes.
If on an average each PHP-FPM process takes ~85MB of RAM on your server, appropriate value for pm.max_children can be calculated as:

pm.max_children = Total RAM dedicated to the web server / Max child process size

The server has 8GB of RAM, so:

pm.max_children = 6144MB / 85MB = 72

You need to take into account any other services running on the machine while calculating memory usage.
Then change the settings as follow:

You can check an average memory usage by single PHP-FPM process with this handy command:

You can use the same steps above to calculate the value for MaxClients for Apache web server – just substitute the php-fpm with httpd.

 

Fonte: http://community.webcorecloud.com/tutorials/how_to_solve_php_fpm_server_reached_max_children/

Facebook Comments
5/5 - (1 vote)