2013-02-22 24 views
14

我正在运行nginx + php-fpm。有什么方法可以让我知道每个PHP进程在做什么?像apache中的扩展mod_status,我可以看到带有PID x的apache进程正在处理URL y。我不确定PHP过程是否知道URL,但获取脚本路径和名称就足够了。如何确定在PHP-FPM过程中执行哪个脚本

回答

24

一些谷歌搜索小时,浏览PHP.net错误跟踪系统后,我已经找到了解决办法。它从PHP 5.3.8或5.3.9开始可用,但似乎没有记录。根据功能请求#54577,状态页面支持选项full,它将单独显示每个工人的状态。因此,例如URL将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 
+3

另一个非常有用的选项是?html,例如:http://server.com/php-status?full&html(它会将输出格式化为html表格,这使得更容易一次查看所有正在运行的脚本) – ivanhoe 2014-05-26 13:37:20

+0

how我可以访问它吗我添加任何参数到nginx配置? – 2015-09-28 14:11:13

+0

@babakfaghihian是的,您需要将该URL(例如'/ php-status')传递给php-fpm。 – Marki555 2015-09-29 11:42:49

6

PHP-FPM有一个内置的状态监视器,虽然它不如mod_status的细节。从PHP-FPM配置文件/etc/php-fpm.d/www.conf(在CentOS 6)

; 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; 

} 
+0

是的,我知道从PHP-FPM这种状态下,我已经在使用它在munin和zabbix监测。但是,它只提供汇总信息而不是按进程信息。 – Marki555 2013-02-22 12:26:44

+0

除了创建自定义日志记录解决方案或设置访问日志处理之外,不要以为除了处理时间之外,您还可以做更多的事情。我确信随着PHP-FPM的成熟,他们将扩展状态报告。 – sjdaws 2013-02-22 12:42:55

+0

最后,我发现状态页面支持每个进程的信息(请参阅我的答案)。 – Marki555 2013-02-22 17:09:56

3

CGI命令行更方便易:

SCRIPT_NAME=/status \ 
SCRIPT_FILENAME=/status \ 
REQUEST_METHOD=GET \ 
cgi-fcgi -bind -connect 127.0.0.1:9000 
+4

另请注意,您必须添加'QUERY_STRING = full'才能返回OP正在查找的内容。将'SCRIPT_FILENAME'改为'/ status?full'不起作用。 – Isius 2015-04-01 17:17:30

+0

您仍然需要通过取消注释'pm.status_path'来启用状态页面;这种方法的优点是它不需要由Web服务器公开。 'SCRIPT_NAME'和'SCRIPT_FILENAME'应该与'php-fpm.conf'文件中的'pm.status_path'相同。最后一个参数('127.0.0.1:9000')是到FCGI服务器的连接,*不是* web服务器 - 它应该是任何'listen'参数在同一个INI文件中。如果它是套接字,则可能需要使用'sudo'来连接,在这种情况下,还可以使用'-E'来告诉'sudo'将环境变量传递给'cgi-fcgi'。 – Wolfgang 2017-04-23 22:50:57

相关问题