对于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 <?xml version="1.0" ?> <status> <pool>www</pool> <process-manager>dynamic</process-manager> <start-time>1514721658</start-time> <start-since>3900</start-since> <accepted-conn>10</accepted-conn> <listen-queue>0</listen-queue> <max-listen-queue>0</max-listen-queue> <listen-queue-len>128</listen-queue-len> <idle-processes>47</idle-processes> <active-processes>1</active-processes> <total-processes>48</total-processes> <max-active-processes>1</max-active-processes> <max-children-reached>0</max-children-reached> <slow-requests>0</slow-requests> </status>[root@cacti vhost]#
[root@cacti vhost]# curl http://127.0.0.1:15681/fpm2status?html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head><title>PHP-FPM Status Page</title></head> <body> <table> <tr><th>pool</th><td>www</td></tr> <tr><th>process manager</th><td>dynamic</td></tr> <tr><th>start time</th><td>31/Dec/2017:20:00:58 +0800</td></tr> <tr><th>start since</th><td>3924</td></tr> <tr><th>accepted conn</th><td>11</td></tr> <tr><th>listen queue</th><td>0</td></tr> <tr><th>max listen queue</th><td>0</td></tr> <tr><th>listen queue len</th><td>128</td></tr> <tr><th>idle processes</th><td>47</td></tr> <tr><th>active processes</th><td>1</td></tr> <tr><th>total processes</th><td>48</td></tr> <tr><th>max active processes</th><td>1</td></tr> <tr><th>max children reached</th><td>0</td></tr> <tr><th>slow requests</th><td>0</td></tr> </table> </body></html>
共同学习,写下你的评论
评论加载中...
作者其他优质文章