Categories
Linux

PHP-FPM configuration of child processes Nginx

If you get this message on your PHP-FPM log

server reached max_children setting (20), consider raising it

You can find this log if you use serverpilot at /var/log/php7.0-fpm-sp.log

To edit your PHP configuration you need to create a settings.conf file in /etc/phpX.Y-sp/fpm-pools.d/APPNAME.d/

Mine looks like this

pm = dynamic # by default on serverpilot is ondemand
pm.max_children = 200 # see below how to calculate
pm.start_servers = 20 # if we restart have this
pm.min_spare_servers = 20 # extra workers waiting
pm.max_spare_servers = 40 # no more than 40 workers waiting to start
pm.max_requests = 5000 # this is really handy will respawn/restart a children after 5000 requests
request_terminate_timeout = 30s; # in case php can not terminate a process this will force it

I have 32GB memory I have calculated thinking that we have 16GB to be used for PHP.

Then restart and ready!

sudo service php7.0-fpm-sp restart

Please see FPM Configuration for more settings and details.

To do this calculations you can check an average memory usage by single PHP-FPM process with this handy command:

ps –no-headers -o “rss,cmd” -C php-fpm | awk ‘{ sum+=$1 } END { printf (“%d%s\n”, sum/NR/1024,”M”) }’

Thanks to myshell.co.uk for this short commands.