{"id":5389,"date":"2017-03-04T15:01:06","date_gmt":"2017-03-04T20:01:06","guid":{"rendered":"https:\/\/www.tecklyfe.com\/?p=5389"},"modified":"2017-03-04T15:01:06","modified_gmt":"2017-03-04T20:01:06","slug":"adjusting-child-processes-php-fpm-nginx-fix-server-reached-pm-max_children-setting","status":"publish","type":"post","link":"https:\/\/www.tecklyfe.com\/adjusting-child-processes-php-fpm-nginx-fix-server-reached-pm-max_children-setting\/","title":{"rendered":"Adjusting Child Processes For PHP-FPM Nginx – Fix Server Reached pm.max_children Setting"},"content":{"rendered":"
As an addition to my previous NGINX articles<\/a>, today we’ll discuss how to adjust the number of child processes for PHP-FPM to fix the common error of “server reached pm.max_children” in the logs. This is a follow-up to the LEMP Install NGINX PHP7 MySQL on Ubuntu 16.04 Server<\/a> or LEMP Install NGINX PHP7 MySQL on CentOS 7 \/ RHEL \/ Fedora<\/a> articles. By default, the pm.max_children is set to 5 when using PHP-FPM.<\/p>\n The most common reasons why your PHP-FPM would reach the max_children are:<\/p>\n Depending on where your PHP-FPM logs are stored, try running one of the following commands:<\/p>\n If you see any lines like the one below, then you’ll want to adjust some of these settings:<\/p>\n To adjust the settings, you’ll need to find your php-fpm.conf<\/strong> or www.conf<\/strong> depending on what version of PHP-FPM you have installed. In my case, I had to edit \/etc\/php\/7.0\/fpm\/pool.d\/www.conf<\/strong>. You’ll want to look for the following settings and make adjustments based on your server specs:<\/p>\n A few of these settings are the default, like pm=dymanic. For the pm.max_requests, the setting should be there but commented out with a ; in front of the line. Delete the ; to uncomment the setting.<\/p>\n To get an idea of what to use for the pm.max_children, you can use this calculation: Also remember, higher isn’t always better. If you have a bad PHP script, these settings won’t resolve your issues. Tweak these settings and see what works best on your server. After you make the changes, you need to restart your PHP-FPM service. Depending on the name of your service, you can try on of the following:<\/p>\n Have you run into these errors in your logs? If so, what are your server specs and what settings worked best for you?<\/p>\n","protected":false},"excerpt":{"rendered":" As an addition to my previous NGINX articles, today we’ll discuss how to adjust the number of child processes for PHP-FPM to fix the common error of “server reached pm.max_children” in the logs. This is a follow-up to the LEMP Install NGINX PHP7 MySQL on Ubuntu 16.04 Server or LEMP Install NGINX PHP7 MySQL on CentOS 7 \/ RHEL \/ Fedora articles. By default, the pm.max_children is set to 5 when using PHP-FPM. Reasons Why You Reach max_children The most common reasons why your PHP-FPM would reach the max_children are: A lot of concurrent site visitors Slow execution of the <\/p>\n","protected":false},"author":1,"featured_media":5390,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1339,1078],"tags":[375,1079,1516,1814,1521,1815,1819,1818,1817,1816],"_links":{"self":[{"href":"https:\/\/www.tecklyfe.com\/wp-json\/wp\/v2\/posts\/5389"}],"collection":[{"href":"https:\/\/www.tecklyfe.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tecklyfe.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tecklyfe.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tecklyfe.com\/wp-json\/wp\/v2\/comments?post=5389"}],"version-history":[{"count":0,"href":"https:\/\/www.tecklyfe.com\/wp-json\/wp\/v2\/posts\/5389\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tecklyfe.com\/wp-json\/wp\/v2\/media\/5390"}],"wp:attachment":[{"href":"https:\/\/www.tecklyfe.com\/wp-json\/wp\/v2\/media?parent=5389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tecklyfe.com\/wp-json\/wp\/v2\/categories?post=5389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tecklyfe.com\/wp-json\/wp\/v2\/tags?post=5389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}Reasons Why You Reach max_children<\/h2>\n
\n
tail -f \/var\/log\/php-fpm\/error.log
\ntail -f \/var\/log\/php7.0-fpm.log<\/code><\/p><\/blockquote>\nserver reached max_children setting (5), consider raising<\/code><\/p><\/blockquote>\n
Adjusting The max_children Setting<\/h2>\n
[php-fpm-pool-settings]
\npm = dynamic
\npm.max_children = 25
\npm.start_servers = 10
\npm.min_spare_servers = 5
\npm.max_spare_servers = 20
\npm.max_requests = 500<\/code><\/p><\/blockquote>\npm.max_children = Total RAM dedicated to the web server \/ Max child process size<\/code>. Remember to leave some RAM for extra services you have running on your system.<\/p>\n
sudo systemctl restart php-fpm
\nsudo systemctl restart php7.0-fpm<\/code><\/p><\/blockquote>\nFinal Thoughts<\/h2>\n