Applicable to:
- Plesk for Linux
Symptoms
-
Websites that have PHP handler set as FPM application served by Apache or FPM application served by nginx at Domains > example.com > PHP Settings load slowly or are not accessible (permanently or periodically) with a 50x error in a web-browser:
PLESK_INFO: 500 Internal Server Error
OR
PLESK_INFO: 502 Bad Gateway
OR
PLESK_INFO: 503 Service Temporarily Unavailable
OR
PLESK_INFO: 504 Gateway Time-out
-
Error messages as below (in bold) appear in the PHP-FPM error logfile
/var/log/php-fpm.log
or/var/log/plesk-phpXX-fpm/error.log
:# grep "server reached max_children setting (X), consider raising it" /var/log/*php*-fpm/error.log* | wc -l
632OR
# grep "unable to read what child say: Bad file descriptor (9)" /var/log/*php*-fpm/error.log* | wc -l
829-
Additionally, on Debian/Ubuntu-based distributions run:
# grep "server reached max_children setting" /var/log/*php*-fpm.log | wc -l
In some cases, the error message can be as follows:
CONFIG_TEXT: [pool example.com] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 4 idle, and 152 total children
-
-
Server performance may decrease due to php-fpm processes that use up to 100% of CPU.
-
If nginx is enabled on the server, one of the following error messages may appear in domain's error logfile
/var/www/vhosts/system/example.com/logs/proxy_error_log
:CONFIG_TEXT: [error] 11456#0: *118348 connect() to unix:///var/www/vhosts/system/example.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 203.0.113.2, server: example.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/example.com/php-fpm.sock:", host: "example.com"
OR
CONFIG_TEXT: [error] 20058#0: *4725139 upstream prematurely closed connection while reading response header from upstream, client: 203.0.113.2, server: example.com, request: "POST /path/to/some/file HTTP/2.0", upstream:
Cause
Child processes of PHP-FPM master process constantly reaches its limit.
Resolution
-
Connect to the Plesk server via SSH.
-
Find out what domains are affected using the command below:
# grep "server reached max_children" /var/log/*php*-fpm/error.log* | cut -d' ' -f5 | tr -d ']' | sort | uniq -c | sort -nr
300 example.com
200 example.net
100 example.org
<...>-
Additionally, on Debian/Ubuntu-based distributions run the following command to scan the log of PHP-FPM by OS vendor:
# grep "server reached max_children setting" /var/log/*php*-fpm.log | cut -d' ' -f5 | tr -d ']' | sort | uniq -c | sort -nr
-
-
Increase the
pm.max_children
limit for them using the instructions below. Note that server performance can be affected ifpm.max_children
is too big.-
Plesk Onyx 17.5 and newer releases
Increasing pm.max_children for a domainStarting from Plesk Onyx 17.5 Update #32, the PHP-FPM limits can be adjusted via Plesk.
-
In Plesk, go to Domains > example.com > PHP Settings > PHP-FPM Settings.
-
Increase the
pm.max_children
value for a domain and apply the changes.In this example, we are setting
pm.max_children
to 20.
Increasing pm.max_children for all domains under a service plan-
In Plesk, go to Service Plans > plan_name > PHP Settings tab > PHP-FPM Settings section.
-
Increase the
pm.max_children
value and click Update & Sync.In this example, we are setting
pm.max_children
to 20.
Note: The changes will not be applied to subscriptions if:
- A subscription is not synced with this service plan (Marked with a blue lock in the Subscriptions menu).
- If the permission Hosting performance settings management is granted in service plan settings at Service Plans > plan_name > Permissions tab.
Click on the picture to enlarge
-
-
Plesk 12.5 and previous releases
Increasing pm.max_children for one domain-
Create the
php.ini
file in domain's system directory/var/www/vhosts/system/example.com/conf/
:# touch /var/www/vhosts/system/example.com/conf/php.ini
-
Open the
php.ini
file in any text editor (for example, vi editor) and add the following records:CONFIG_TEXT: [php-fpm-pool-settings]
pm.max_children = 20 -
Run the command below to apply the changes:
# /usr/local/psa/bin/php_settings -u
-
-
Comments
10 comments
Great help and tutorial ! Thanks a lot
Possible to apply this setting to all domains with single file editing? I have lots of domains to be configured 1 by 1
@Sharul Hafiz You can check the article mentioned in Additional Information section - https://support.plesk.com/hc/en-us/articles/115001201949
Keep in mind that increasing of pm.max_children parameter for all domains can affect the server performance significantly. It is better to filter only affected domains in /var/log/plesk-phpXX-fpm/error.log file
===
grep "server reached max_children setting" /var/log/plesk-phpXX-fpm/error.log
===
and adjust max_children just for them.
@Nikolay What is the limit of pm.max_children? let say if I have 10GB free ram.
@Sharul
The setting is purely depends on amount of traffic for the website. Try to double the default value (from 5 to 10) and monitor the site for several days.
If the same error appears again, analyze the time period between reaching MaxChildren. In case the time like several minutes, double the value again (from 10 to 20), in case the error appears once a day, just add one more child to the configured value (20 to 21).
Typically, 20 is more than enough for medium-loaded websites.
This line
is wrong, as it should be
May you insert
in Additional PHP directives field of PHP Settings page for domain?
Hello Marco,
Both files (/var/log/php-fpm/error.log and /var/log/plesk-phpXX-fpm/error.log) exist on the filesystem. The first is used to store errors from system php-fpm, and the second is used when we are speaking about php-fpm which is provided bu Plesk.
Meanwhile, I have edited the article in this way:
# grep "server reached max_children setting" /var/log/*php*-fpm/error.log | awk '{print $5}' | sort -n | uniq -c
As for the second question, Additional PHP directives field is used to insert configuration directives in /var/www/vhosts/system/example.com/conf/php.ini file (configuration file for php itself), however pm.max_children directive should be added to the configuration file of php-fpm pool (/var/www/vhosts/system/example.com/conf/php.ini).
So, this is two different files. And now Plesk could manage only php settings, but not php fpm pool settings.
If you would like Plesk to manage php fpm pool settings, vote for this feature on Plesk Uservoice portal.
@Konstantin
You provided the same path for both php.ini files and said these were two different files.
Hello @Lars,
Thank you for noticing. Indeed, additional directives are stored in/var/www/vhosts/system/example.com/conf/php.ini and PHP-FPM settings are stored in /opt/plesk/php/X.X/etc/php-fpm.d/example.com.conf.
As it is stated in the article, now it is possible to change PHP-FPM settings in Pleks GUI.
Please sign in to leave a comment.