I have a setup of nginx + php-fpm on my server.
FPM's pool configuration looks like this:
[www]
user = root
group = root
listen = /run/php-fpm.sock
listen.owner = root
listen.group = root
pm = ondemand
pm.max_children = 50
pm.process_idle_timeout = 10s
pm.max_requests = 500
pm.status_path = /server-status
catch_workers_output = yes
My first expectation is, that no child php-fpm processes are started unless there's an incoming request. Unfortunately, when I start php-fpm I promptly see 2 processes:
10 ? S 0:00 php-fpm: master process (/etc/php/7.1/fpm/php-fpm.conf)
37 ? S 0:00 php-fpm: pool www
So, one process is pre-forked for some reason.
My second expectation is that all processes idling for more than 10s will be killed. I run a test which results in the creation of 13 processes. After 1 minute or so (no more requests performed) around 5 processes are idling. Why is it so?
Related
Today, I want to enable the slow-logs with PHP-FPM, and then I configured some parameters into the php-fpm.conf.
In the end, I have a problem, it can create the slow-log, but can't write any contents into the slow-log.
Can someone help me, thanks a lot?
My website is running in Docker, and my Nginx use Unix Sockets to communicate with PHP-FPM, and Nginx running as Root
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm7.sock;
}
My php-fpm.conf is
[www123]
user = app
group = app
listen = /var/run/php-fpm7.sock
listen.owner = app
listen.group = app
listen.mode = 0666
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
slowlog = /app/logs/my_slow_log/$pool.log.slow
request_slowlog_timeout = 1s
Next step, I created the directory app/logs/my_slow_log and restart the PHP-FPM. It created the file www123.log.slow in directory app/logs/my_slow_log, but the file permission/user/group is wrong. It was 600 / root / root
/app/logs/my_slow_log # ls -al
total 4
drwxr-xr-x 2 app app 28 May 16 19:32 .
drwxrwxrwx 3 app app 4096 May 16 19:00 ..
-rw------- 1 root root 0 May 16 19:32 www123.log.slow
There are some running processes
app/logs/my_slow_log # ps -ef
PID USER TIME COMMAND
1 root 0:00 runsvdir /etc/service
7 root 0:00 runsv nginx
8 root 0:00 runsv javabridge
9 root 0:00 runsv php7
10 root 0:00 java -jar /usr/lib/jvm/java-1.8-openjdk/jre/lib/ext/JavaBridge.jar SERVLET_LOCAL:8080
11 root 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf -g daemon off;
12 root 0:00 {php-fpm7} php-fpm: master process (/etc/php7/php-fpm.conf)
13 root 0:00 nginx: worker process
14 root 0:00 nginx: worker process
15 root 0:00 nginx: worker process
16 root 0:00 nginx: worker process
22 app 0:00 {php-fpm7} php-fpm: pool www123
23 app 0:00 {php-fpm7} php-fpm: pool www123
I find the master php-fpm process was run as Root, but the child process was run as app, so I modified the php-fpm.conf change
user = root
group = root
listen.owner = root
listen.group = root
then restart PHP-FPM, I got some error message
ERROR: [pool www123] please specify user and group other than root
ERROR: FPM initialization failed
It can't work as Root.
I think the problem was /app/logs/my_slow_log/www123.log.slow created by PHP-FPM master process with root, and my child process was user app, so it can't write anything into the slow-log.
I didn't know what truly happened, can anybody help me?
Thanks.
You can use this command (chmod 777 my_slow_log), I think Log directory permission is not important.
I have on my server running custom php process /etc/php/7.1/fpm/master.d/custom_name.conf
root 2620 0.0 2.6 412440 26808 ? Ss May31 0:33 php-fpm: master process (/etc/php/7.1/fpm/master.d/custom_name.conf)
root 6822 0.0 0.0 13384 916 pts/1 S+ 19:58 0:00 grep php
root 27575 0.0 1.1 410680 11828 ? Ss May31 0:33 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
www-data 27578 0.0 0.5 410680 5760 ? S May31 0:00 php-fpm: pool www
www-data 27579 0.0 0.5 410680 5760 ? S May31 0:00 php-fpm: pool www
And config exists in directory /etc/php/fpm/master.d/custom_name.conf.
But i don't even know how to restart this service. I changed file config and tried service php7.1-fpm stop but the process is still alive.
If I try service php7.1-fpm start or service php7.1-fpm restart process /etc/php/7.1/fpm/php-fpm.conf appears, but old process still working. Maybe command service php7.1-fpm has parameters where i can pass extra config data. Example config file from master.d directory
Here is config of this file /etc/php/7.1/fpm/master.d/custom_name.conf:
[global]
pid = /run/php7.1-fpm.custom_name.pid
error_log = /var/log/php7.1-fpm.log
[custom_name]
user = custom_name
group = custom_name
listen = /var/run/php7.1-fpm.custom_name.sock
listen.owner = www-data
listen.group = www-data
pm = ondemand
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.status_path = /fpm-status
chdir = /
catch_workers_output = yes
php_admin_value[session.save_path] = /var/www/custom_name.com/sessions
php_admin_value[open_basedir] = /var/www/custom_name.com/code/public:/tmp:/usr/share/php:/var/www/tools/
php_admin_flag[log_errors] = on
php_admin_flag[opcache.enable] = on
Thanks in advance
Finally hoster said me how restart this process:
sudo service php7.2-fpm#custom_name restart
Having set the pool to static with max_children to 5 I would expect the metric "active processes" to be 5 or below. Sending 10 concurrent requests will have "active processes" report more than 5 (e.g. 10, 12, 25, ...).
Is this valid behaviour?
Pool configuration:
# grep -v ";" /usr/local/etc/php-fpm.d/www.conf | grep -Ev "^$"
[www]
user = www-data
group = www-data
listen = 127.0.0.1:9000
pm = static
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.process_idle_timeout = 10s
pm.max_requests = 500
pm.status_path = /status
ping.response = pong
slowlog = log/$pool.log.slow
request_slowlog_timeout = 0
request_terminate_timeout = 0
Expected result:
Metric "active processes" from /status should be below 5.
Actual result:
Metric "active processes" from /status is above 5.
According to the PHP FPM documentation when pm is set to static the only setting that determines the number of child processes is pm.max_children. As you expect, that should determine the start and max number.
A couple things to consider:
After changing the configuration did you restart both PHP-FPM and NGINX ? Something like:
sudo service php-fpm5 restart
sudo service nginx restart
Is it possible you are altering the wrong config file (perhaps one that is in the wrong path?). You might try changing some other value and confirm that it is affecting the web server as intended.
Is it possible that you have multiple pools configured and that the /status page is giving you a report for multiple pools.
php-fpm crash every morning at 7pm (I don't have specific cron at this time), log say :
WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 39 idle, and 180 total children
Server hardware :
nproc : 40
RAM: 256Go
here is www.conf of php-fpm :
[www]
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data
listen.mode = 0666
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 350
pm.start_servers = 40
pm.min_spare_servers = 40
pm.max_spare_servers = 70
pm.process_idle_timeout = 60s;
pm.max_requests = 500
request_terminate_timeout = 0
chdir = /
php_flag[display_errors] = off
php_admin_value[error_reporting] = 0
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 1024M
php_admin_value[session.save_path] = /tmp/
I already try to increase max_children value but it change nothing
I had VPS with CentOS 6.4 64bit. There is running Nginx 1.4.4 and PHP-FPM 5.5.6. I'm trying to make long-polling requests. However, if server is already processing one request, he doesn't respond to other. This mean, that if I have script with:
sleep(60);
PHP doesn't process other request. I must wait for 60 seconds. PHP status page is:
pool: www
process manager: dynamic
start time: 26/Nov/2013:22:02:00 +0100
start since: 148
accepted conn: 170
listen queue: 0
max listen queue: 0
listen queue len: 128
idle processes: 1
active processes: 49
total processes: 50
max active processes: 49
max children reached: 1
slow requests: 0
And je conf.d/www.conf:
[www]
listen.allowed_clients = 127.0.0.1
user = apache
group = apache
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
pm.status_path = /status
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache