51, php-fpm Pool, php-fpm slow execution log, Open_basedir, PHP-FPM process Management
First, the pool of PHP-FPM
Pool: Right. The right-most column of PS aux. It's the pond.
# CD/USR/LOCAL/PHP-FPM/ETC
# cat php-fpm.conf//supports defining multiple pools
[Global]
PID =/usr/local/php-fpm/var/run/php-fpm.pid
Error_log =/usr/local/php-fpm/var/log/php-fpm.log
[www]//This is a pool
Listen =/tmp/php-fcgi.sock
#listen = 127.0.0.1:9000
Listen.mode = 666
user = PHP-FPM
Group = PHP-FPM
PM = dynamic
Pm.max_children = 50
Pm.start_servers = 20
Pm.min_spare_servers = 5
Pm.max_spare_servers = 35
Pm.max_requests = 500
Rlimit_files = 1024
Each pool can listen for different sockets or TCP/IP.
If Nginx has several sites, each site can use a pool, the advantage is that when a certain php502 (502 is probably not enough PHP resources), if many sites are using the same pool, if a programmer wrote the wrong thing, It will run out of PHP resources so that other sites will be 502, so it is necessary to use a separate pool for each site.
PHP-FPM can continue to increase pool:
# VIM php-fpm.conf//Added a
[Mrx.com]
Listen =/tmp/mrx.sock
#listen = 127.0.0.1:9000
Listen.mode = 666
user = PHP-FPM
Group = PHP-FPM
PM = dynamic
Pm.max_children = 50
Pm.start_servers = 20
Pm.min_spare_servers = 5
Pm.max_spare_servers = 35
Pm.max_requests = 500
Rlimit_files = 1024
#/usr/local/php-fpm/sbin/php-fpm-t
[29-apr-2018 22:10:01] Notice:configuration file/usr/local/php-fpm/etc/php-fpm.conf Test is successful
[Email protected] etc]#/ETC/INIT.D/PHP-FPM Reload
Reload Service PHP-FPM Done
# PS aux |grep php-fpm//Can see the rightmost www and mrx.com
PHP-FPM 1536 0.0 0.2 227228 4708? S 22:11 0:00 Php-fpm:pool www
PHP-FPM 1537 0.0 0.2 227228 4708? S 22:11 0:00 Php-fpm:pool www
PHP-FPM 1538 0.0 0.2 227228 4708? S 22:11 0:00 Php-fpm:pool www
PHP-FPM 1539 0.0 0.2 227228 4704? S 22:11 0:00 Php-fpm:pool mrx.com
PHP-FPM 1540 0.0 0.2 227228 4704? S 22:11 0:00 Php-fpm:pool mrx.com
PHP-FPM 1541 0.0 0.2 227228 4704? S 22:11 0:00 Php-fpm:pool mrx.com
How to use:
# cd/usr/local/nginx/conf/vhost/
# Vim Test.com.conf
Location ~ \.php$
{
Include Fastcgi_params;
Fastcgi_pass Unix:/tmp/php-fcgi.sock; Set Php-fcgi.sock here
Fastcgi_index index.php;
Fastcgi_param Script_filename/data/wwwroot/test.com$fastcgi_script_name;
}
# Vim Aaa.com.conf
Location ~ \.php$//So two sites are separated from each other.
{
Include Fastcgi_params;
Fastcgi_pass unix:/tmp/Mrx.sock;
Fastcgi_index index.php;
Fastcgi_param script_filename/data/wwwroot/default$fastcgi _script_name;
}
If Test.com.conf has 50 requests, the request is full, then the request will be reported 502, because there is no extra PHP to provide it with services, and mrx.com this site is not affected, because it uses another pool.
# tail. /nginx.conf
Tcp_nodelay on;
gzip on;
Gzip_min_length 1k;
Gzip_buffers 4 8k;
Gzip_comp_level 5;
Gzip_http_version 1.1;
Gzip_types text/plain application/x-javascript text/css text/htm
Application/xml;
include vhost/*.conf; There is this one in Nginx, PHP-FPM also supports
}
# CD/USR/LOCAL/PHP-FPM/ETC
# Vim Php-fpm.conf
[Global]
PID =/usr/local/php-fpm/var/run/php-fpm.pid
Error_log =/usr/local/php-fpm/var/log/php-fpm.log
Include = etc/php-fpm.d/*.conf
Add a line to global.
and split the contents of the pool below. Copy and delete all of the following content first.
# mkdir PHP-FPM.D
[Email protected] etc]# CD php-fpm.d/
Because you just defined PHP-FPM.D, create a directory
[Email protected] php-fpm.d]# vim www.conf
[WWW]
Listen =/tmp/php-fcgi.sock
#listen = 127.0.0.1:9000
Listen.mode = 666
user = PHP-FPM
Group = PHP-FPM
PM = dynamic
Pm.max_children = 50
Pm.start_servers = 20
Pm.min_spare_servers = 5
Pm.max_spare_servers = 35
Pm.max_requests = 500
Rlimit_files = 1024
# Vim Mrx.conf
[Mrx.com]
Listen =/tmp/mrx.sock
#listen = 127.0.0.1:9000
Listen.mode = 666
user = PHP-FPM
Group = PHP-FPM
PM = dynamic
Pm.max_children = 50
Pm.start_servers = 20
Pm.min_spare_servers = 5
Pm.max_spare_servers = 35
Pm.max_requests = 500
#/usr/local/php-fpm/sbin/php-fpm-t
[29-apr-2018 23:32:09] Notice:configuration file/usr/local/php-fpm/etc/php-fpm.conf Test is successful
#/etc/init.d/php-fpm Restart
Gracefully shutting down php-fpm. Done
Starting php-fpm Done
Again PS aux |grep php-fpm can see, is the same effect, mrx.com in front, www in the back.
Second, php-fpm slow execution log (very useful)
PHP Web site, the proposed use of LNMP, one of the reasons is that you can analyze the slow log of PHP, website slow can be performed by slow log analysis.
# cd/usr/local/php-fpm/etc/php-fpm.d/
# Vim Www.conf
Request_slowlog_timeout = 1 //means record log for more than 1 seconds, generally set 2 seconds for
These two lines are added to the last side.
Slowlog =/usr/local/php-fpm/var/log/www-slow.log//path of the log
#/usr/local/php-fpm/sbin/php-fpm-t
[01-may-2018 16:42:04] Notice:configuration file/usr/local/php-fpm/etc/php-fpm.conf Test is successful
[Email protected] php-fpm.d]#/ETC/INIT.D/PHP-FPM Reload
Reload Service PHP-FPM Done
# ls/usr/local/php-fpm/var/log///Check logs have no build
Php-fpm.log Www-slow.log
Configure Nginx Virtual host test.com.conf, change Unix:/tmp/php-fcgi.sock to Unix:/tmp/www.sock, and reload Nginx service.
# vim/data/wwwroot/test.com/sleep.php
<?php
echo "Test slow Log";
Sleep (2);
echo "Done";
?>
# Vim/usr/local/php-fpm/etc/php.ini
Display_errors = on here to change the off to on the browser can see the error log, the line here to off, you can not let others in the browser to see your error message.
# curl-x127.0.0.1:80 test.com/sleep.php Test, it will be 2 seconds slower and then logged into the slow execution log.
# Cat/usr/local/php-fpm/var/log/www-slow.log
Sleep ()/data/wwwroot/test.com/sleep.php:3
This line indicates that the 3rd line of the file is slow. So if the website is slow, you can view this slow execution log slow.log.
Third, PHP-FPM definition Open_basedir
Previously defined in php.ini Open_basedir, if there are multiple sites on the server, it is not appropriate to define in php.ini. Open_basedir can be done for each pond.
# vim/usr/local/php-fpm/etc/php-fpm.d/ www.conf
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/Add this line configuration, when this line configuration is wrong, it will be 404, here is the correct test.com.
#/etc/init.d/php-fpm Restart
# curl-x127.0.0.1:80 Test.com/3.php-i The effect of writing a mistake.
http/1.1 404 Not Found
# curl-x127.0.0.1:80 Test.com/3.php-i the correct effect.
http/1.1 OK
# Vim/usr/local/php-fpm/etc/php.ini
Display_errors = off on change back off, the line here to OFF, you can not let others in the browser to see your error message.
Log_errors = On the correct way is to record the error message in a file on the server.
Error_log = syslog is defined below this line.
Error_log =/usr/local/php-fpm/var/log/php_errors.log A newly added line.
Error_reporting = E_all Defines the log level, all records.
# ls/usr/local/php-fpm/var/log/First check if there's php_errors.log this file
Php-fpm.log Www-slow.log
# Touch/usr/local/php-fpm/var/log/php_errors.log didn't touch a
# chmod 777/usr/local/php-fpm/var/log/php_errors.log permissions changed to 777 to prevent the normal write.
When www.com.conf write a mistake:
php_admin_value[open_basedir]=/data/wwwroot/ wwtest.com :/tmp/
#/etc/init.d/php-fpm Restart
# Cat/usr/local/php-fpm/var/log/php_errors.log look at the error log
[02-may-2018 21:48:14 UTC] PHP Warning:Unknown:open_basedir restriction in effect. File (/data/wwwroot/test.com/3.php) is not within the allowed path (s): (/data/wwwroot/wwtest.com :/tmp/) in Unknown on line 0 not wwtest.com
# Vim Www.com.conf
php_admin_value[open_basedir]=/data/wwwroot/ test.com :/tmp/
Change back to Test.com
Iv. PHP-FPM Process Management
[email protected] php-fpm.d]# cat www.conf
[WWW]
Listen =/tmp/php-fcgi.sock
#listen = 127.0.0.1:9000
Listen.mode = 666
user = PHP-FPM
Group = PHP-FPM
PM = dynamic/Active process management, can be static (static), dynamic.
Pm.max_children = 50//maximum number of sub-processes, PS aux can be viewed. static when only this line takes effect, with static when the direct start is 50, so use dynamic.
Pm.start_servers = 20//Number of processes that will start when the service is started
Pm.min_spare_servers = 5//Defines the minimum number of child processes in the idle period, and if this value is reached, PHP-FPM automatically derives the new child process.
Pm.max_spare_servers = 35//Defines the maximum number of child processes in the idle period, or, if higher than this value, to start cleaning up idle child processes.
Pm.max_requests = 500//defines the maximum number of requests processed by the same child process, that is, at most one php-fpm child process can handle so many requests, when this value is reached, it automatically exits. If you do not quit this child process will always exist, in case there is a problem with this child process.
Rlimit_files = 1024
Request_slowlog_timeout = 1
Slowlog =/usr/local/php-fpm/var/log/www-slow.log
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
# PS aux |grep mrx.com |wc-l
21 This is because mrx.com defines the number of processes that start at startup is 20, and if these processes are not used, these idle processes are destroyed, the limit is destroyed, and a minimum of 5 child processes are preserved.
# PS aux |grep php-fpm |wc-l
42
These parameters can be customized to their own needs.
51, PHP-FPM Pool, php-fpm slow execution log, Open_basedir, php-fpm