12.21 PHP-FPM's Pool
PHP-FPM supports the definition of multiple pool, each of which can listen to different sockets or different TCP/IP;
If Nginx has a number of different sites, then each site can use a pool;
If all the sites are using the same pool, when it is not enough for a PHP resource, or other reasons cause 502, the site is a problem, then all sites are not normal use;
Therefore, it is necessary for us to isolate different sites and use different pool.
Set up multiple pool:
[Email protected] ~]# vim/usr/local/php-fpm/etc/php-fpm.conf
[Email protected] ~]#/usr/local/php-fpm/sbin/php-fpm-t[17-mar-2018 22:31:02] notice:configuration file/usr/local/ php-fpm/etc/php-fpm.conf test is successful[[email protected] ~]#/etc/init.d/php-fpm reloadreload service php-fpm done[ [Email protected] ~]# PS aux|grep php-fpm
With two pool to use at this point, another site is defined under the pool of aming.com
[Email protected] ~]# vim/usr/local/nginx/conf/vhost/aaa.com.conf
In order for the different pool to display more clearly, the parameter information of different pool can be separated into different conf.
[[email protected] ~]# cd/usr/local/php-fpm/etc/[[email protected] etc]# mkdir php-fpm.d/[[email protected] etc]# CD php- fpm.d/
Then separate the two different pool spreads defined in the original php-fpm.conf
[Email protected] php-fpm.d]# vim www.conf
[Email protected] php-fpm.d]# vim aming.conf
Delete information from the pool in the original php-fpm.conf, and add include = etc/php-fpm.d/*.conf in [global]
(This is similar to the configuration method for different vhost in Nginx)
[Email protected] php-fpm.d]# vim/usr/local/php-fpm/etc/php-fpm.conf
[Email protected] php-fpm.d]#/usr/local/php-fpm/sbin/php-fpm-t[17-mar-2018 23:00:48] notice:configuration file/usr /local/php-fpm/etc/php-fpm.conf test is successful[[email protected] php-fpm.d]#/ETC/INIT.D/PHP-FPM Restartgracefully shutting down php-fpm. Donestarting php-fpm done[[email protected] php-fpm.d]# PS aux|grep php-fpm
Aming.com before www, so the pool came into effect
12.22 php-fpm Slow execution log
Objective: In order to record the reason of slow website visit, it is convenient to find the reason
• Increase the configuration of the request time-out record:
[Email protected] ~]# vim/usr/local/php-fpm/etc/php-fpm.d/www.conf
[Email protected] ~]#/usr/local/php-fpm/sbin/php-fpm-t[18-mar-2018 14:01:03] notice:configuration file/usr/local/ php-fpm/etc/php-fpm.conf test is successful[[email protected] ~]#/etc/init.d/php-fpm reloadreload service php-fpm done[ [Email protected] ~]# Ls/usr/local/php-fpm/var/log/php-fpm.log Www-slow.log
Write a PHP script that simulates PHP execution for more than 1 seconds
Because Php-fcgi.sock is test.com this site consumer, it is created under test.com cleep.php
[Email protected] ~]# vim/data/wwwroot/test.com/sleep.php
[Email protected] ~]# curl-x127.0.0.1:80 test.com/sleep.phptest slow logdone[[email protected] ~]# cat/usr/local/php-f pm/var/log/www-slow.log[18-mar-2018 14:51:15] [pool www] pid 1578script_filename =/data/wwwroot/test.com/sleep.php[ 0X00007F39874B9280] Sleep ()/data/wwwroot/test.com/sleep.php:2
(The 2nd line of the sleep.php script appears above is slow)
• General request Time Request_slowlog_timeout = definition is greater than 2 seconds, because most PHP execution time is between 1-2 seconds, the definition of more than 2 seconds can filter out a lot of unwanted information.
12.23 Open_basedir
[Email protected] ~]# vim/usr/local/php-fpm/etc/php-fpm.d/www.conf
[Email protected] ~]# curl-x127.0.0.1:80 test.com/3.php-ihttp/1.1 Okserver:nginx/1.12.2date:sun, 2018 07:1 1:24 gmtcontent-type:text/html; charset=utf-8connection:keep-alivex-powered-by:php/5.6.30
• Configure the PHP-FPM error log:
• Turn off display error:display_errors = Off
• Select logging level:Error_reportint = E_all
• Turn On error log switch:log_errors = On
• Configuration error log save location:error_log =/usr/local/php-fpm/var/log/php_errors.log
• The error log path will need to be recreated if it does not exist
[Email protected] ~]# touch/usr/local/php-fpm/var/log/php_errors.log[[email protected] ~]# chmod 777! $chmod 777/usr/l Ocal/php-fpm/var/log/php_errors.log
• We change the configuration Open_basedir in www.conf, continue to access, view the error log
[Email protected] ~]# vim/usr/local/php-fpm/etc/php-fpm.d/www.conf
[Email protected] ~]#/etc/init.d/php-fpm restartgracefully shutting down php-fpm. Donestarting php-fpm done[[email protected] ~]# curl-x127.0.0.1:80 test.com/3.phpno input file specified. [Email protected] ~]# curl-x127.0.0.1:80 test.com/3.php-ihttp/1.1 404 Not Foundserver:nginx/1.12.2date:sun, 20 Mar 07:30:30 gmtcontent-type:text/html; Charset=utf-8connection:keep-alivex-powered-by:php/5.6.30[[email protected] ~]# cat/usr/local/php-fpm/var/log/php _errors.log[object Object]
(Path is incorrect)
[Email protected] ~]# vim/usr/local/php-fpm/etc/php-fpm.d/www.conf
[Email protected] ~]#/etc/init.d/php-fpm restartgracefully shutting down php-fpm. Donestarting php-fpm done[[email protected] ~]#!curlcurl-x127.0.0.1:80 test.com/3.php-ihttp/1.1-OKSERVER:NGINX/1. 12.2date:sun, Mar 2018 07:36:44 gmtcontent-type:text/html; charset=utf-8connection:keep-alivex-powered-by:php/5.6.30
(can be accessed)
12.24 PHP-FPM Process Management
• Configure Process Management parameters:
PM = dynamic process Management, can also be static
Pm.max_children = 50//maximum number of sub-processes, PS aux can be viewed
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, the PHP-FPM service 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 a child process, that is, in a PHP-FPM child process can handle so many requests, when this value is reached, it automatically exits
[Email protected] ~]# cat/usr/local/php-fpm/etc/php-fpm.d/www.conf
Pm=dynamic dynamic, start with 20 first, then generate or destroy the child process according to the requirement
If dynamic is changed to static, then the red box configuration will no longer take effect, start generating 50 processes directly
[Email protected] ~]# vim/usr/local/php-fpm/etc/php-fpm.d/www.conf
[Email protected] ~]#/etc/init.d/php-fpm restartgracefully shutting down php-fpm. Donestarting php-fpm done[[email protected] ~]# PS aux|grep php-fpm
(www This pool has 50 processes)
If there are errors, please correct, learn from each other and progress together!!!
2018-3-19 13 weeks 1 lessons php-fpm pool, slow log, process, Open_basedir