The pool of PHP-FPM
When a lot of PHP sites share a pool, if one of the sites affect the pool, will cause other sites also problems, in order to avoid this problem, need to create a new pool for each site, isolation, security services
1, [[email protected] ~]# vim/usr/local/php-fpm/etc/php-fpm.conf
New:
[Test.com]
Listen =/tmp/test.sock
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
2, [[email protected] ~]#/usr/local/php-fpm/sbin/php-fpm-t
3, [[email protected] ~]#/ETC/INIT.D/PHP-FPM Reload
4, [[email protected] ~]# vim/usr/local/nginx/conf/vhost/aaa.com.conf
5. Add the following:
[Email protected] ~]# Vim/usr/local/nginx/conf/vhost/aaa.com.conf.bak
Server
{
Listen default_server;
The default virtual host is marked #有 ' Default_server '
server_name aaa.com;
Index index.html index.htm index.php;
Root/data/wwwroot/default;
Location ~ \.php$
{
Include Fastcgi_params;
Fastcgi_pass Unix:/tmp/test.sock;
Fastcgi_index index.php;
Fastcgi_param Script_filename/data/wwwroot/default$fastcgi_script_name;
}
}
6, [[email protected] ~]#/etc/init.d/nginx Reload
7, you can see that there are two of the pool
[[Email protected] ~]# PS aux |grep php-fpm
PHP-FPM 8403 0.0 0.2 227144 4808? S 17:22 0:00 Php-fpm:pool www
PHP-FPM 8423 0.0 0.2 227144 4812? S 17:22 0:00 Php-fpm:pool test.com
To add a php-fpm.conf child configuration file
To facilitate the management of php-fpm.conf on the configuration file, similar to Nginx on the virtual host conf, you can also separate fill in the file
1.
[Email protected] php-fpm.d]# vi/usr/local/php-fpm/etc/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 =/usr/local/php-fpm.d/*.conf
2.
[Email protected] php-fpm.d]# vim/usr/local/php-fpm.d/test.conf
[Test.com]
Listen =/tmp/test.sock
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
3.
[Email protected] php-fpm.d]# vim/usr/local/php-fpm.d/www.conf
[WWW]
Listen =/tmp/php-fcgi.sock
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
4.
[Email protected] php-fpm.d]#/usr/local/php-fpm/sbin/php-fpm-t
5.
[Email protected] php-fpm.d]#/ETC/INIT.D/PHP-FPM Reload
Verify: Is there a 2 pool
[Email protected] php-fpm.d]# Ps-ef | grep php-fpm
PHP-FPM Slow Execution Log
When PHP access slows down, you can see which PHP script is causing the slow log like MySQL by slow log
1. What's new
[Email protected] php-fpm.d]# vim/usr/local/php-fpm.d/www.conf
[WWW]
Listen =/tmp/php-fcgi.sock
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
Request_slowlog_timeout = 1
#请求超过1秒就记录到日志里
Slowlog =/usr/local/php-fpm/var/log/www-slow.log
2. Experimental script writing
[Email protected] php-fpm.d]# vim/data/wwwroot/test.com/sleep.php
#输出test Slow LOG,SLEEP2 s, end
<?php
echo "Test slow Log";
Sleep (2);
echo "Done";
?>
[Email protected] php-fpm.d]#/ETC/INIT.D/PHP-FPM Reload
3. Verification:
[Email protected] php-fpm.d]# curl-x127.0.0.1:80 test.com/sleep.php
Test slow Logdone[[email protected]
[Email protected] php-fpm.d]# Tail/usr/local/php-fpm/var/log/www-slow.log
#记录了日志
[16-nov-2017 17:41:59] [Pool www] pid 8669
Script_filename =/data/wwwroot/test.com/sleep.php
[0x00007f15620aa2e8] Sleep ()/data/wwwroot/test.com/sleep.php:3
Open_basedir settings
When a server runs multiple sites, use Open_basedir to limit the range of directories on the servers that each site can access. In the PHP-FPM service, you can set open _ Basedir for each pool.
1. What's new
[Email protected] php-fpm.d]# vim/usr/local/php-fpm.d/www.conf
[WWW]
Listen =/tmp/php-fcgi.sock
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
Request_slowlog_timeout = 1
#请求超过1秒就记录到日志里
Slowlog =/usr/local/php-fpm/var/log/www-slow.log
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
2.
[Email protected] php-fpm.d]# vim/data/wwwroot/test.com/1.php
<?php
echo "This is Open_basedir";
3. Verification:
[Email protected] php-fpm.d]#/ETC/INIT.D/PHP-FPM Reload
Reload Service PHP-FPM Done
[Email protected] php-fpm.d]# curl-x127.0.0.1:80 test.com/1.php
This is Open_basedir
PHP-FPM Process Management
PHP-FPM in the pool configuration parameter resolution:
[Email protected] php-fpm.d]# vim www.conf
[WWW]
Listen =/tmp/php-fcgi.sock
Listen.mode = 666
user = PHP-FPM
Group = PHP-FPM
PM = dynamic
; Defines how the process is started (dynamic, static)
Only if this is set to dynamic, the following configuration will take effect, and if you choose Static, pre-production of the set process, will not change dynamically
Pm.max_children = 50
; Maximum number of child processes that can be started
Pm.start_servers = 20
; Sets the number of processes that are initially started
Pm.min_spare_servers = 5
; indicates that PHP-FPM must have at least a few sub-processes when idle
Pm.max_spare_servers = 35
Indicates that PHP-FPM is idle for up to a few child processes
Pm.max_requests = 500
; Indicates the maximum number of requests a child process can accept
Rlimit_files = 1024
; Indicates how many file handles each child process has opened
Request_slowlog_timeout = 1
When the request starts logging in more than 1 seconds
Slowlog =/usr/local/php-fpm/var/log/www-slow.log
; Log storage Address
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
This article is from the "Discover new things" blog, make sure to keep this source http://jacksoner.blog.51cto.com/5802843/1982498
PHP-FPM pool, php-fpm slow execution log, Open_basedir, PHP-FPM process Management