目录
一、php-fpm的pool
二、php-fpm慢执行日志
三、open_basedir
四、php-fpm进程管理
一、php-fpm的pool
和LAMP不同的是,在LNMP架构中,php-fpm作为独立的一个服务存在。
php-fpm的配置文件为/usr/local/php-fpm/etc/php-fpm.conf,它同样也支持
include语句,类似于nginx.conf里面的include。
Nignx可以配置多个虚拟主机,php-fpm同样也支持配置多个pool,每一个pool可以监听一个端口,也可以监听一个socket。
- 查看php-fpm配置文件
[root@minglinux-01 ~] cd /usr/local/php-fpm/etc/
[root@minglinux-01 /usr/local/php-fpm/etc] ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[root@minglinux-01 /usr/local/php-fpm/etc] cat 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
[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
- 修改php-fpm.conf文件增加pool
[root@minglinux-01 /usr/local/php-fpm/etc] vim php-fpm.conf
1 [global]
2 pid = /usr/local/php-fpm/var/run/php-fpm.pid
3 error_log = /usr/local/php-fpm/var/log/php-fpm.log
4 [www]
5 listen = /tmp/php-fcgi.sock
6 listen.mode = 666
7 user = php-fpm
8 group = php-fpm
9 pm = dynamic
10 pm.max_children = 50
11 pm.start_servers = 20
12 pm.min_spare_servers = 5
13 pm.max_spare_servers = 35
14 pm.max_requests = 500
15 rlimit_files = 1024
16 //增加以下内容
17 [ming]
18 listen = /tmp/ming.sock //监听/tmp/www.sock
19 listen.mode = 666
20 user = php-fpm
21 group = php-fpm
22 pm = dynamic
23 pm.max_children = 50
24 pm.start_servers = 20
25 pm.min_spare_servers = 5
26 pm.max_spare_servers = 35
27 pm.max_requests = 500
28 rlimit_files = 1024
- 测试
[root@minglinux-01 /usr/local/php-fpm/etc] /usr/local/php-fpm/sbin/php-fpm -t //检查配置
[03-Dec-2018 21:01:56] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@minglinux-01 /usr/local/php-fpm/etc] /etc/init.d/php-fpm reload
Reload service php-fpm /etc/init.d/php-fpm: 第 142 行:kill: (876) - 没有那个进程
done
[root@minglinux-01 /usr/local/php-fpm/etc] service php-fpm start
Starting php-fpm done
[root@minglinux-01 /usr/local/php-fpm/etc] /etc/init.d/php-fpm reload //重载配置
Reload service php-fpm done
[root@minglinux-01 /usr/local/php-fpm/etc] ps aux |grep php-fpm
root 5190 0.2 0.2 123752 4952 ? Ss 21:02 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 5191 0.0 0.2 123692 4696 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5192 0.0 0.2 123692 4696 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5193 0.0 0.2 123692 4696 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5194 0.0 0.2 123692 4696 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5195 0.0 0.2 123692 4700 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5196 0.0 0.2 123692 4700 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5197 0.0 0.2 123692 4700 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5198 0.0 0.2 123692 4704 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5199 0.0 0.2 123692 4704 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5200 0.0 0.2 123692 4704 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5201 0.0 0.2 123692 4704 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5202 0.0 0.2 123692 4704 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5203 0.0 0.2 123692 4704 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5204 0.0 0.2 123692 4704 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5205 0.0 0.2 123692 4704 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5206 0.0 0.2 123692 4704 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5207 0.0 0.2 123692 4704 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5208 0.0 0.2 123692 4704 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5209 0.0 0.2 123692 4704 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5210 0.0 0.2 123692 4704 ? S 21:02 0:00 php-fpm: pool www
php-fpm 5211 0.0 0.2 123692 4700 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5212 0.0 0.2 123692 4700 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5213 0.0 0.2 123692 4700 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5214 0.0 0.2 123692 4704 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5215 0.0 0.2 123692 4708 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5216 0.0 0.2 123692 4708 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5217 0.0 0.2 123692 4708 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5218 0.0 0.2 123692 4708 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5219 0.0 0.2 123692 4708 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5220 0.0 0.2 123692 4708 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5221 0.0 0.2 123692 4708 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5222 0.0 0.2 123692 4708 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5223 0.0 0.2 123692 4708 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5224 0.0 0.2 123692 4708 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5225 0.0 0.2 123692 4708 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5226 0.0 0.2 123692 4708 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5227 0.0 0.2 123692 4708 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5228 0.0 0.2 123692 4708 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5229 0.0 0.2 123692 4708 ? S 21:02 0:00 php-fpm: pool ming
php-fpm 5230 0.0 0.2 123692 4712 ? S 21:02 0:00 php-fpm: pool ming
root 5232 0.0 0.0 112720 984 pts/1 R+ 21:02 0:00 grep --color=auto php-fpm
可以看到php-fpm已经有www和ming两个pool了。这样就可以在Nginx不同的虚拟主机中调用不同的pool,从而达到相互隔离的目的,两个pool互不影响。
- 指定虚拟主机中调用不同的pool
[root@minglinux-01 /usr/local/php-fpm/etc] cd /usr/local/nginx/conf/vhost/
[root@minglinux-01 /usr/local/nginx/conf/vhost] ls
aaa.com.conf load.conf proxy.conf ssl.conf test.com.conf
[root@minglinux-01 /usr/local/nginx/conf/vhost] vim test.com.conf
···
50 location ~ \.php$
51 {
52 include fastcgi_params;
53 fastcgi_pass unix:/tmp/php-fcgi.sock; //这里监听的是www的socket地址
54 fastcgi_index index.php;
55 fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
56 }
···
[root@minglinux-01 /usr/local/nginx/conf/vhost] vim aaa.com.conf
···
8 location ~ \.php$
9
10 {
11 include fastcgi_params;
12 fastcgi_pass unix:/tmp/ming.sock //这里监听的是ming的socket地址
13 fastcgi_index index.php;
14 fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name;
15
16 }
···
nginx有多个站点,若只有一个php的pool,当某个站点或某些站点将pool的资源耗尽,就会导致其他使用该pool的站点出现502错误。如果每个站点使用各自独立的pool就不会有这种问题。
- php-fpm配置多个pool的另一种方式
[root@minglinux-01 /usr/local/nginx/conf/vhost] vim /usr/local/php-fpm/etc/php-fpm.conf
//php-fpm.conf改为如下形式
1 [global]
2 pid = /usr/local/php-fpm/var/run/php-fpm.pid
3 error_log = /usr/local/php-fpm/var/log/php-fpm.log
4 include = etc/php-fpm.d/*.conf
[root@minglinux-01 /usr/local/nginx/conf/vhost] cd /usr/local/php-fpm/etc/
[root@minglinux-01 /usr/local/php-fpm/etc] mkdir php-fpm.d
[root@minglinux-01 /usr/local/php-fpm/etc] cd php-fpm.d/
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] vim www.conf
1 [www]
2 listen = /tmp/php-fcgi.sock
3 listen.mode = 666
4 user = php-fpm
5 group = php-fpm
6 pm = dynamic
7 pm.max_children = 50
8 pm.start_servers = 20
9 pm.min_spare_servers = 5
10 pm.max_spare_servers = 35
11 pm.max_requests = 500
12 rlimit_files = 1024
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] vim ming.conf
1 [ming]
2 listen = /tmp/ming.sock
3 listen.mode = 666
4 user = php-fpm
5 group = php-fpm
6 pm = dynamic
7 pm.max_children = 50
8 pm.start_servers = 20
9 pm.min_spare_servers = 5
10 pm.max_spare_servers = 35
11 pm.max_requests = 500
12 rlimit_files = 1024
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] /usr/local/php-fpm/sbin/php-fpm -t
[03-Dec-2018 21:48:25] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] ps aux |grep php-fpm
root 5381 0.0 0.2 227372 4980 ? Ss 21:49 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 5382 0.0 0.2 227312 4712 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5383 0.0 0.2 227312 4712 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5384 0.0 0.2 227312 4712 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5385 0.0 0.2 227312 4712 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5386 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5387 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5388 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5389 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5390 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5391 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5392 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5393 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5394 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5395 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5396 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5397 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5398 0.0 0.2 227312 4720 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5399 0.0 0.2 227312 4720 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5400 0.0 0.2 227312 4720 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5401 0.0 0.2 227312 4720 ? S 21:49 0:00 php-fpm: pool ming
php-fpm 5402 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5403 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5404 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5405 0.0 0.2 227312 4716 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5406 0.0 0.2 227312 4720 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5407 0.0 0.2 227312 4720 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5408 0.0 0.2 227312 4720 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5409 0.0 0.2 227312 4720 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5410 0.0 0.2 227312 4720 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5411 0.0 0.2 227312 4720 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5412 0.0 0.2 227312 4720 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5413 0.0 0.2 227312 4720 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5414 0.0 0.2 227312 4724 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5415 0.0 0.2 227312 4724 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5416 0.0 0.2 227312 4724 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5417 0.0 0.2 227312 4724 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5418 0.0 0.2 227312 4724 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5419 0.0 0.2 227312 4724 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5420 0.0 0.2 227312 4724 ? S 21:49 0:00 php-fpm: pool www
php-fpm 5421 0.0 0.2 227312 4724 ? S 21:49 0:00 php-fpm: pool www
root 5423 0.0 0.0 112720 984 pts/1 S+ 21:49 0:00 grep --color=auto php-fpm
二、php-fpm慢执行日志
php的网站,建议使用LNMP,当php网站运行慢时php-fpm的慢执行日志可以帮助快速地追踪到问题点。
- 开启和查看php-fpm的慢执行日志
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] vim www.conf
//再最后面增加如下两行内容
1 [www]
2 listen = /tmp/php-fcgi.sock
3 listen.mode = 666
4 user = php-fpm
5 group = php-fpm
6 pm = dynamic
7 pm.max_children = 50
8 pm.start_servers = 20
9 pm.min_spare_servers = 5
10 pm.max_spare_servers = 35
11 pm.max_requests = 500
12 rlimit_files = 1024
13 request_slowlog_timeout = 1
14 slowlog = /usr/local/php-fpm/var/log/www-slow.log
第一行定义超时时间,即PHP的脚本执行时间只要超过1秒就会记录日志,第二行定义慢执行日志的路径和名字。以后遇到PHP网站访问卡顿的问题时,要记得去查看这个慢执行日志。
- 测试
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] /usr/local/php-fpm/sbin/php-fpm -t
[03-Dec-2018 22:01:46] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] /etc/init.d/php-fpm reload
Reload service php-fpm done
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] ls /usr/local/php-fpm/var/log
php-fpm.log www-slow.log
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] cat /usr/local/php-fpm/var/log/www-slow.log //已生成的慢日志为空
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] cat /usr/local/nginx/conf/vhost/test.com.conf
···
50 location ~ \.php$
51 {
52 include fastcgi_params;
53 fastcgi_pass unix:/tmp/php-fcgi.sock; //监听的是www的socket地址
54 fastcgi_index index.php;
55 fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
56 }
···
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] vim /data/wwwroot/test.com/sleep.php
//创建测试脚本如下
1 <?php
2 echo "test slow log";
3 sleep(2);
4 echo "\ndone\n";
5 ?>
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] curl -x127.0.0.1:80 test.com/sleep.php //测试
test slow log
done
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] cat /usr/local/php-fpm/var/log/www-slow.log
[03-Dec-2018 22:15:34] [pool www] pid 5482
script_filename = /data/wwwroot/test.com/sleep.php
[0x00007fde0e9d8298] sleep() /data/wwwroot/test.com/sleep.php:3 //具体到行
通过php-fpm的慢执行日志可以非常清晰地了解到PHP的脚本哪里执行时间长,它可以定位到具体的行。
三、open_basedir
当服务器上有多个网站时,不适合在php.ini文件中定义openbasedir,可以在虚拟主机配置文件中定义或在php-fpm中定义
httpd可以针对每个虚拟主机设置一个open_basedir,php-fpm同样也可以针对不同的pool设置不同的open_basedir。
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] vim www.conf
1 [www]
2 listen = /tmp/php-fcgi.sock
3 listen.mode = 666
4 user = php-fpm
5 group = php-fpm
6 pm = dynamic
7 pm.max_children = 50
8 pm.start_servers = 20
9 pm.min_spare_servers = 5
10 pm.max_spare_servers = 35
11 pm.max_requests = 500
12 rlimit_files = 1024
13 request_slowlog_timeout = 1
14 slowlog = /usr/local/php-fpm/var/log/www-slow.log
15 php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/ //openbasedir路径定义不正确会无法访问
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] curl -x127.0.0.1:80 test.com/3.php -I
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Mon, 03 Dec 2018 14:50:43 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30
- openbasedir路径定义错误
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] vim www.conf
1 [www]
2 listen = /tmp/php-fcgi.sock
3 listen.mode = 666
4 user = php-fpm
5 group = php-fpm
6 pm = dynamic
7 pm.max_children = 50
8 pm.start_servers = 20
9 pm.min_spare_servers = 5
10 pm.max_spare_servers = 35
11 pm.max_requests = 500
12 rlimit_files = 1024
13 request_slowlog_timeout = 1
14 slowlog = /usr/local/php-fpm/var/log/www-slow.log
15 php_admin_value[open_basedir]=/data/wwwroot/ming.com:/tmp/ //定义错误
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] /etc/init.d/php-fpm reload
Reload service php-fpm done
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] curl -x127.0.0.1:80 test.com/3.php -I
HTTP/1.1 404 Not Found
Server: nginx/1.12.2
Date: Mon, 03 Dec 2018 14:51:45 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30
- php-fpm错误日志
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] vim /usr/local/php-fpm/etc/php.ini
···
106 error_reporting = E_ALL //定义错误日志级别
···
466 display_errors = Off //Off浏览器不显示错误信息。错误信息不应显示再浏览器中,应保存到指定文件中
···
487 log_errors = On //开启错误日志记录功能
···
575 error_log = /usr/local/php-fpm/var/log/php_errors.log //日志保存路径
···
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] ls /usr/local/php-fpm/var/log/
php-fpm.log www-slow.log
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] touch /usr/local/php-fpm/var/log/php_errors.log //手动创建错误日志文件
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] chmod 777 /usr/local/php-fpm/var/log/php_errors.log //修改较高权限以防错误日志写入不成功
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] !curl
curl -x127.0.0.1:80 test.com/3.php -I
HTTP/1.1 404 Not Found
Server: nginx/1.12.2
Date: Mon, 03 Dec 2018 15:09:59 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] cat /usr/local/php-fpm/var/log/php_errors.log
[03-Dec-2018 15:09:59 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/ming.com:/tmp/) in Unknown on line 0
[03-Dec-2018 15:09:59 UTC] PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] vim www.conf
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] !curl
curl -x127.0.0.1:80 test.com/3.php -I
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Mon, 03 Dec 2018 15:17:49 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30
3.php文件在test.com路径下,而open_basedir路径限制在ming.com路径下,因此访问受限。将路径改正后即可访问成功。
四、php-fpm进程管理
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] cat www.conf
···
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
···
配置含义:
pm = dynamic定义php-fpm的子进程启动模式,dynamic为动态模式;一开始只启动少量的子进程,根据实际需求,动态地增加或者减少子进程,最多不会超过pm.max_children定义的数值。另外一种模式为static,这种模式下子进程数量由pm.max_children决定,一次性启动这么多,不会减少也不会增加。
pm.start_servers针对dynamic模式,它定义php-fpm服务在启动服务时产生的子进程数量。后期再根据访问量增加,如果服务器较空闲时也会自动销毁进程。
pm.min_spare_servers针对dynamic模式,它定义在空闲时段子进程数的最少数量。若php-fpm进程空闲就会销毁部分进程,但至少会保留5个子进程。
pm.max_spare_servers也是针对dynamic模式的,它定义在空闲时段子进程数的最大值,如果高于这个数值就开始清理空闲的子进程。
pm.max_requests针对dynamic模式,它定义一个子进程最多处理的请求数,也就是说在一个php-fpm的子进程中最多可以处理这么多请求,当达到这个数值时,它会自动退出,再派生另外的子进程处理后续请求。
- 修改配置文件
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] vim www.conf
//修改了pm.start_servers = 5
···
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
···
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] /etc/init.d/php-fpm reload
Reload service php-fpm done
[root@minglinux-01 /usr/local/php-fpm/etc/php-fpm.d] ps aux |grep php-fpm
root 5824 0.5 0.2 227372 4948 ? Ss 23:39 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 5825 0.0 0.2 227312 4712 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5826 0.0 0.2 227312 4712 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5827 0.0 0.2 227312 4712 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5828 0.0 0.2 227312 4712 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5829 0.0 0.2 227312 4716 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5830 0.0 0.2 227312 4716 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5831 0.0 0.2 227312 4716 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5832 0.0 0.2 227312 4716 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5833 0.0 0.2 227312 4716 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5834 0.0 0.2 227312 4716 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5835 0.0 0.2 227312 4716 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5836 0.0 0.2 227312 4716 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5837 0.0 0.2 227312 4716 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5838 0.0 0.2 227312 4716 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5839 0.0 0.2 227312 4720 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5840 0.0 0.2 227312 4720 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5841 0.0 0.2 227312 4720 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5842 0.0 0.2 227312 4720 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5843 0.0 0.2 227312 4720 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5844 0.0 0.2 227312 4720 ? S 23:39 0:00 php-fpm: pool ming
php-fpm 5845 0.0 0.2 227312 4716 ? S 23:39 0:00 php-fpm: pool www
php-fpm 5846 0.0 0.2 227312 4716 ? S 23:39 0:00 php-fpm: pool www
php-fpm 5847 0.0 0.2 227312 4716 ? S 23:39 0:00 php-fpm: pool www
php-fpm 5848 0.0 0.2 227312 4716 ? S 23:39 0:00 php-fpm: pool www
php-fpm 5849 0.0 0.2 227312 4720 ? S 23:39 0:00 php-fpm: pool www
root 5851 0.0 0.0 112720 980 pts/1 S+ 23:39 0:00 grep --color=auto php-fpm
可以看到php-fpm服务在启动服务时产生的子进程数量变为了5个