KenoKivabe

Your Essential Queries

Author
Chris Moore
22 Jul, 2022

How To set max_children for PHP-FPM

While using php-fpm sometimes we may face some pm.max_children related warnings inside error log file, or sometime php-fpm: pool consumes high cpu continuously.

  1. WARNING: [pool www] server reached pm.max_children setting (5),
  2. consider raising it  

The reason of the issue may raise because of not configuring pm.max_children properly.

What is pm.max_children ?

pm.max_children can be called process manager of php-fpm. By setting max_children value we can set up how many process php-fpm can create while serving requests.

We can check php-fpm error logs inside /var/log directory in ubuntu/debian system.

  1. //PHP 5.0  
  2. tail -f /var/log/php5-fpm.log  
  3. //PHP 7.0  
  4. sudo tail -f /var/log/php7.0-fpm.log  
  5. //PHP 7.1  
  6. sudo tail -f /var/log/php7.1-fpm.log  
  7. //PHP 7.2  
  8. sudo tail -f /var/log/php7.2-fpm.log  

How to calculate pm.max_children for php-fpm ?

1) open the www.conf file

  1. sudo vi /etc/php/7.0/fpm/pool.d/www.conf  

You can see the default assigned values

  1. pm.max_children = 5  
  2. pm.start_servers = 2  
  3. pm.min_spare_servers = 4  
  4. pm.max_spare_servers = 8  

2) Now follow the following method to calculate the max_children number

[Total Available RAM] - [Reserved RAM] - [10% buffer] = [Available RAM for PHP]
Results:
[Available RAM for PHP] / [Average Process Size] = [max_children]
pm.max_children = [max_children]
pm.start_servers = [25% of max_children]
pm.min_spare_servers = [25% of max_children]
pm.max_spare_servers = [75% of max_children]

Also you can use the virtual calculator to calculate.

Share: