我正在運行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. 如何確定在BASH中哪一行腳本選擇更快?
- 3. 如何確定使用TPL時將執行哪個線程?
- 4. 如何在存儲過程中執行批處理腳本?
- 5. 如何在執行MSBuild腳本的過程中暫停?
- 6. 如何在構建過程中執行批處理腳本?
- 7. 如何在APEX SQL腳本中執行過程?
- 8. shell腳本在執行過程中執行的分支數
- 9. 如何確定在delphi中哪個事件調用過程
- 10. 如何確定哪些存儲過程正在執行(MSSQL 2008 R2)
- 11. 執行PHP腳本的確切程度?
- 12. 如何在Python腳本中執行整個Javascript程序
- 13. 確定哪個腳本最後完成
- 14. 如何通過python執行shell腳本
- 15. 腳本未正確執行
- 16. 如何確定列表中的哪個可執行文件正在運行
- 17. 如何在Linux中執行python腳本?
- 18. 如何在java中執行perl腳本?
- 19. 如何在腳本中執行grep?
- 20. 如何在php中執行腳本
- 21. 如何在cygwin中執行shell腳本?
- 22. 如何在VSTS中執行腳本
- 23. 如何在私有類的腳本中正確執行sql
- 24. 執行存儲過程輸出腳本
- 25. 通過SSH執行遠程python腳本
- 26. 如何確定的函數實例在執行過程?
- 27. 如何在腳本中執行TeamCity遠程運行?
- 28. 如何確定哪個URL訪問了腳本
- 29. 單擊按鈕(Web應用程序)後執行哪個腳本?
- 30. 如何知道在大量代碼中執行哪個java腳本函數?
另一個非常有用的選項是?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