2013-02-22 111 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