如何确定在 PHP-FPM 进程中正在执行哪个脚本
我正在运行nginx + php-fpm。有什么办法可以让我知道每个PHP进程在做什么?类似于apache中的扩展mod_status,我可以看到带有PID x的apache进程正在处理URL y。我不确定PHP进程是否知道URL,但是获取脚本路径和名称就足够了。
我正在运行nginx + php-fpm。有什么办法可以让我知道每个PHP进程在做什么?类似于apache中的扩展mod_status,我可以看到带有PID x的apache进程正在处理URL y。我不确定PHP进程是否知道URL,但是获取脚本路径和名称就足够了。
经过几个小时的谷歌搜索和浏览 PHP.net 错误跟踪系统,我找到了解决方案。它自 PHP 5.3.8 或 5.3.9 起可用,但似乎没有文档记录。基于功能请求 #54577,状态页面支持 选项 ,该选项将分别显示每个工作线程的状态。因此,例如URL将是,示例输出看起来像:full
http://server.com/php-status?full
pid: 22816
state: Idle
start time: 22/Feb/2013:15:03:42 +0100
start since: 10933
requests: 28352
request duration: 1392
request method: GET
request URI: /ad.php?zID=597
content length: 0
user: -
script: /home/web/server.com/ad/ad.php
last request cpu: 718.39
last request memory: 1310720
PHP-FPM有一个内置的状态监视器,尽管它不像mod_status那么详细。從 php-fpm config file (在 CentOS 6 上)/etc/php-fpm.d/www.conf
; The URI to view the FPM status page. If this value is not set, no URI will be
; recognized as a status page. By default, the status page shows the following
; information:
; accepted conn - the number of request accepted by the pool;
; pool - the name of the pool;
; process manager - static or dynamic;
; idle processes - the number of idle processes;
; active processes - the number of active processes;
; total processes - the number of idle + active processes.
; The values of 'idle processes', 'active processes' and 'total processes' are
; updated each second. The value of 'accepted conn' is updated in real time.
; Example output:
; accepted conn: 12073
; pool: www
; process manager: static
; idle processes: 35
; active processes: 65
; total processes: 100
; By default the status page output is formatted as text/plain. Passing either
; 'html' or 'json' as a query string will return the corresponding output
; syntax. Example:
; http://www.foo.bar/status
; http://www.foo.bar/status?json
; http://www.foo.bar/status?html
; Note: The value must start with a leading slash (/). The value can be
; anything, but it may not be a good idea to use the .php extension or it
; may conflict with a real PHP file.
; Default Value: not set
;pm.status_path = /status
如果启用此功能,则可以将路径从nginx传递到PHP-FPM的套接字/端口,并且可以查看状态页面。
nginx.conf:
location /status {
include fastcgi_params;
fastcgi_pass unix:/var/lib/php/php-fpm.sock;
}