我正在运行nginx + php-fpm。有什么方法可以让我知道每个PHP进程在做什么?像apache中的扩展mod_status,我可以看到带有PID x的apache进程正在处理URL y。我不确定PHP过程是否知道URL,但获取脚本路径和名称就足够了。如何确定在PHP-FPM过程中执行哪个脚本
回答
一些谷歌搜索小时,浏览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
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;
}
CGI命令行更方便易:
SCRIPT_NAME=/status \
SCRIPT_FILENAME=/status \
REQUEST_METHOD=GET \
cgi-fcgi -bind -connect 127.0.0.1:9000
另请注意,您必须添加'QUERY_STRING = full'才能返回OP正在查找的内容。将'SCRIPT_FILENAME'改为'/ status?full'不起作用。 – Isius 2015-04-01 17:17:30
您仍然需要通过取消注释'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
- 1. 确定哪个PHP脚本执行特定的mysql查询
- 2. 如何确定我的脚本在哪个页面上运行
- 3. 如何确定在BASH中哪一行脚本选择更快?
- 4. 如何确定使用TPL时将执行哪个线程?
- 5. 如何在存储过程中执行批处理脚本?
- 6. 如何在执行MSBuild脚本的过程中暂停?
- 7. 如何在PostgreSql中执行存储过程的python脚本?
- 8. 如何在APEX SQL脚本中执行过程?
- 9. 如何在构建过程中执行批处理脚本?
- 10. 当执行shell脚本时,如何知道它正在执行哪个行号,
- 11. shell脚本在执行过程中执行的分支数
- 12. 如何确定在执行过程中停止org.quartz.JobDetail的时间?
- 13. 如何确定Redis中Lua脚本的执行时间?
- 14. 如何确定在delphi中哪个事件调用过程
- 15. 如何确定哪些存储过程正在执行(MSSQL 2008 R2)
- 16. 如何确定哪个版本的Python适合脚本?
- 17. 确定已执行的脚本 - JSR 223
- 18. 确定从脚本执行的位置
- 19. 执行PHP脚本的确切程度?
- 20. 如何在Python脚本中执行整个Javascript程序
- 21. 确定哪个脚本最后完成
- 22. 如何通过python执行shell脚本
- 23. 如何确定脚本何时加载并执行
- 24. 如何检查Python脚本的哪一行正在执行?
- 25. 如何确定哪个视图执行了一个命令
- 26. 脚本未正确执行
- 27. 如何确定列表中的哪个可执行文件正在运行
- 28. 如何在java中执行perl脚本?
- 29. 如何在C++中执行powershell脚本?
- 30. 如何在bash中执行php脚本?
另一个非常有用的选项是?html,例如:http://server.com/php-status?full&html(它会将输出格式化为html表格,这使得更容易一次查看所有正在运行的脚本) – ivanhoe 2014-05-26 13:37:20
how我可以访问它吗我添加任何参数到nginx配置? – 2015-09-28 14:11:13
@babakfaghihian是的,您需要将该URL(例如'/ php-status')传递给php-fpm。 – Marki555 2015-09-29 11:42:49