# Adjusting child processes for PHP-FPM (Nginx) ## Determine if the max_children limit has been reached. - `sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log` ## Determine system RAM and average pool size memory. - `free -h` - All fpm processes: `ps -ylC php-fpm7.0 --sort:rss` - Average memory: `ps --no-headers -o "rss,cmd" -C php-fpm7.0 | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'` - All fpm processes memory: `ps -eo size,pid,user,command --sort -size | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' | grep php-fpm` ## Calculate (pm.max_children = Total RAM dedicated to the web server / Max child process size) - System RAM: 2GB - Average Pool size: 85Mb - `pm.max_children = 1500MB / 85MB = 17` ## Configure `sudo vim /etc/php/7.0/fpm/pool.d/www.conf` ``` pm.max_children = 17 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 pm.max_request = 1000 ```