php-fpm.conf有两个至关重要的参数:一个是”max_children”,另一个是”request_terminate_timeout”.
如果pm设置为static,那么其实只有pm.max_children这个参数生效,系统会开启设置数量的php-fpm进程。
如果pm设置为dynamic,那么pm.max_children参数失效,后面3个参数生效。
pm.max_children:静态方式下开启的php-fpm进程数量。pm.start_servers:动态方式下的起始php-fpm进程数量。pm.min_spare_servers:动态方式下的最小php-fpm进程数量。pm.max_spare_servers:动态方式下的最大php-fpm进程数量。
使用unix socket,即在nginx配置文件中
设定 fastcgi_pass=unix:/dev/shm/phpfpm.sock;
把php的socket文件phpfpm.sock放在/dev/shm中的理由是/dev/shm是内存设备,放在这个里面读取速度快
配置php-fpm的文件,修改参数 listen ,将
listen =127.0.0.1:9000 修改为
listen =/dev/shm/phpfpm.sock
如果php-fpm启动后生成的phpfpm.sock文件的权限不不足,nginx 无法读取,会报502错误,配置 listen.mode = 0666,即可完美解决问题
request_slowlog_timeout = 10s
slowlog = log/$pool.log.slow
rlimit_files = 1024
默认1024,此值可以不需要配置
重启php-fpm
/usr/local/php/sbin/php-fpm restart
设置php-fpm使用socket文件
在配置文件/usr/local/php/etc/php-fpm.conf文件中找到
#listen = 127.0.0.1:9000
listen = /opt/aspire/product/weixin/php7/php-cgi.sock
重启php-fpm
/usr/local/php/sbin/php-fpm restart
配置nginx
location ~ \.php$ {
root html;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/opt/aspire/product/weixin/php7/php-cgi.sock
重启nginx
/usr/local/nginx/sbin/nginx -s reload
开启nginx和php-fpm的status状态监控
启用nginx status配置
location ~ \.php$ {
root html;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/opt/aspire/product/weixin/php7/php-cgi.sock
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /opt/aspire/product/weixin/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
location /ngx_status {
allow 10.153.86.6;
deny all;
stub_status on;
access_log off;
}
}
nginx_status
nginx status 参数说明
active connections – 活跃的连接数量
server accepts handled requests — 总共处理了4个连接 , 成功创建4次握手, 总共处理了4个请求
reading — 读取客户端的连接数.
writing — 响应数据到客户端的数量
waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.
vim /etc/php/7.0/fpm/pool.d/www.conf
pm.status_path = /fpm_status
server {
#listen 80;
listen
80
default_server
;
root /var/www/html
;
index index
.php
index
.html
index
.htm
;
server_name
127.0.0.1
;
location ~ \
.php
$ { include snippets/fastcgi-php
.conf
;
fastcgi_pass unix:/run/php/php7
.0
-fpm
.sock
;
} location ~ /fpm_status$ { allow
127.0.0.1
;
deny all
;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name
;
include fastcgi_params
;
fastcgi_pass unix:/run/php/php7
.0
-fpm
.sock
;
}}
curl http://127.0.0.1/fpm_status
php-fpm 参数说明
pool #fpm池名称,大多数为www
process manager #进程管理方式dynamic或者static
start time #启动日志,如果reload了fpm,时间会更新
start since #运行时间
accepted conn #当前池接受的请求数
listen queue #请求等待队列,如果这个值不为0,那么需要增加FPM的进程数量
max listen queue #请求等待队列最高的数量
listen queue len #socket等待队列长度
idle processes #空闲进程数量
active processes #活跃进程数量
total processes #总进程数量
max active processes #最大的活跃进程数量(FPM启动开始计算)
max children reached
#程最大数量限制的次数,如果这个数量不为0,那说明你的最大进程数量过小,可以适当调整。