php-fpm status,使用php-fpm状态页观察当前的php-fpm状态

对于php-fpm的参数设置,其内置的几个参数例如pm.max_children,pm.start_servers等这几个参数到底该设置最多为多少才合适。其实这几个参数往往取决于当前的连接数情况,而大多数情况下,我们很难断定当前的连接数情况对于我们的pm等几个参数是否合适。所以借助于php-fpm状态页可以很方便的告诉我们这几个参数的设置是否合适。

1.开启php-fpm的状态页

要开启php-fpm的状态页其实很简单在nginx的配置文件中加入:[root@cacti vhost]# cat fpmstatus.conf

server {

listen  127.0.0.1:15681;

location ~^/fpmstatus$ {

#auth_basic "status page";

#fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;

#include fastcgi_params;

include fastcgi.conf;

#fastcgi_pass unix:/var/run/php5-fpm.sock;

fastcgi_pass 127.0.0.1:9000;

}

}

2.在php-fpm.conf配置文件中开启pm.status_path = /status 此处的status可以是自己定义的名称

具体配置文件如下:[root@cacti vhost]#  cat /usr/local/php/etc/php-fpm.conf

[global]

pid = /usr/local/php/var/run/php-fpm.pid

error_log = /data/wwwlogs/fpm-err.log

log_level = notice

events.mechanism = epoll

;process.priority = -19

[www]

listen = 127.0.0.1:9000

listen.backlog = 65535

listen.allowed_clients = 127.0.0.1

listen.owner = www

listen.group = www

listen.mode = 0666

user = www

group = www

pm = dynamic

pm.status_path = /fpmstatus

pm.max_children = 1000

pm.start_servers = 48

pm.min_spare_servers = 24

pm.max_spare_servers = 96

;access.format = "%R - %u %t %T \"%m %r%Q%q\" %s %f %d"

;access.log = /data/wwwlogs/pool.access.log

request_terminate_timeout = 60

;request_slowlog_timeout = 2

;slowlog = /data/wwwlogs/fpm-slow.log

3.在服务器上curl,来查看php-fpm的状态页[root@localhost etc]# curl http://127.0.0.1:15681/fpmstatus

pool:                 www

process manager:      dynamic

start time:           28/Dec/2017:01:22:37 +0800

start since:          331138

accepted conn:        15026663

listen queue:         0

max listen queue:     0

listen queue len:     0

idle processes:       74

active processes:     97

total processes:      171

max active processes: 186

max children reached: 0

slow requests:        0

4.php-fpm的状态页中各个参数的介绍:

下面介绍每个参数的作用:

pool:php-fpm池的名称,一般都是应该是www

process manage:进程的管理方法,php-fpm支持三种管理方法,分别是static,dynamic和ondemand,一般情况下都是dynamic

start time:php-fpm启动时候的时间,不管是restart或者reload都会更新这里的时间

start since:php-fpm自启动起来经过的时间,默认为秒

accepted conn:当前接收的连接数

listen queue:在队列中等待连接的请求个数,如果这个数字为非0,那么最好增加进程的fpm个数

max listen queue:从fpm启动以来,在队列中等待连接请求的最大值

listen queue len:等待连接的套接字队列大小

idle processes:空闲的进程个数

active processes:活动的进程个数

total processes:总共的进程个数

max active processes:从fpm启动以来,活动进程的最大个数,如果这个值小于当前的max_children,可以调小此值

max children reached:当pm尝试启动更多的进程,却因为max_children的限制,没有启动更多进程的次数。如果这个值非0,那么可以适当增加fpm的进程数

slow requests:慢请求的次数,一般如果这个值未非0,那么可能会有慢的php进程,一般一个不好的mysql查询是最大的祸首。

5.full详解(php-fpm状态页参数)

如果想看到更加详细的信息,可以使用localhost/status?full查看每个子进程更加额外的信息,拿其中的一个子进程来说明:pid: 6917

state: Idle

start time: 17/Aug/2014:15:27:46 -0400

start since: 8399

requests: 35

request duration: 69295

request method: GET

request URI: /member.php?mod=logging&action=login&infloat=yes&frommessage&inajax=1&ajaxtarget=messagelogin

content length: 0

user: -

script: /usr/local/nginx/html/member.php

last request cpu: 72.16

last request memory: 3145728

pid – 进程PID,可以单独kill这个进程. You can use this PID to kill a long running process.

state – 当前进程的状态 (Idle, Running, …)

start time – 进程启动的日期

start since – 当前进程运行时长

requests – 当前进程处理了多少个请求

request duration – 请求时长(微妙)

request method – 请求方法 (GET, POST, …)

request URI – 请求URI

content length – 请求内容长度 (仅用于 POST)

user – 用户 (PHP_AUTH_USER) (or ‘-’ 如果没设置)

script – PHP脚本 (or ‘-’ if not set)

last request cpu – 最后一个请求CPU使用率。

last request memorythe - 上一个请求使用的内存

这里的都比较好理解,主要看下content length和user

content length:这里记录的是POST请求的内容长度.

user:如果设置了PHP_AUTH_USER就会显示对于的值,否则显示为0.

这里需要注意的是如果state的状态为空闲的话,那么这些相关的信息将会以最后请求的服务相关,否则信息取决于当前请求的服务.

6 php-fpm其他参数json、xml、html介绍:

php-fpm状态页比较个性化的一个地方是它可以带参数,可以带参数json、xml、html并且前面三个参数可以分别和full做一个组合。curl

{"pool":"www","process manager":"dynamic","start time":1514721658,"start since":3847,"accepted conn":9,"listen queue":0,"max listen queue":0,"listen queue len":128,"idle processes":47,"active processes":1,"total processes":48,"max active processes":1,"max children reached":0,"slow requests":0}[root@cacti vhost]#[root@cacti vhost]# curl http://127.0.0.1:15681/fpm2status?xml

www

dynamic

1514721658

3900

10

0

0

128

47

1

48

1

0

0

[root@cacti vhost]#[root@cacti vhost]# curl http://127.0.0.1:15681/fpm2status?html

html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

PHP-FPM Status Page
poolwww
process managerdynamic
start time31/Dec/2017:20:00:58 +0800
start since3924
accepted conn11
listen queue0
max listen queue0
listen queue len128
idle processes47
active processes1
total processes48
max active processes1
max children reached0
slow requests0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值