Your Essential Queries
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.
- WARNING: [pool www] server reached pm.max_children setting (5),
- 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.
- //PHP 5.0
- tail -f /var/log/php5-fpm.log
- //PHP 7.0
- sudo tail -f /var/log/php7.0-fpm.log
- //PHP 7.1
- sudo tail -f /var/log/php7.1-fpm.log
- //PHP 7.2
- sudo tail -f /var/log/php7.2-fpm.log
How to calculate pm.max_children for php-fpm ?
1) open the www.conf file
- sudo vi /etc/php/7.0/fpm/pool.d/www.conf
You can see the default assigned values
- pm.max_children = 5
- pm.start_servers = 2
- pm.min_spare_servers = 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.