Как определить, какой script выполняется в процессе PHP-FPM
Я запускаю nginx + php-fpm. Есть ли способ узнать, что делает каждый из процессов PHP? Что-то вроде расширенного mod_status в apache, где я вижу, что процесс apache с PID x обрабатывает URL y. Я не уверен, знает ли PHP-процесс URL-адрес, но получить путь и имя script будет достаточно.
Ответы
Ответ 1
После некоторых часов работы с поисковыми системами и просмотра системы отслеживания ошибок 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
Ответ 2
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;
}
Ответ 3
Командная строка cgi более удобна:
SCRIPT_NAME=/status \
SCRIPT_FILENAME=/status \
REQUEST_METHOD=GET \
cgi-fcgi -bind -connect 127.0.0.1:9000