Reputation: 6850
I am running nginx + php-fpm. Is there any way how can I know what is each of the PHP processes doing? Something like extended mod_status in apache, where I can see that apache process with PID x is processing URL y. I'm not sure if the PHP process knows the URL, but getting the script path and name will be sufficient.
Upvotes: 32
Views: 52901
Reputation: 4082
There is also a PHP function called fpm_get_status()
<?php print_r(fpm_get_status()); ?>
Array
(
[pool] => example.com
[process-manager] => ondemand
[start-time] => 1722156649
[start-since] => 42082
[accepted-conn] => 208729
[listen-queue] => 0
[max-listen-queue] => 0
[listen-queue-len] => 0
[idle-processes] => 7
[active-processes] => 12
[total-processes] => 19
[max-active-processes] => 18
[max-children-reached] => 0
[slow-requests] => 0
[procs] => Array
(
[0] => Array
(
[pid] => 2576722
[state] => Running
[start-time] => 1722160069
[start-since] => 38662
[requests] => 289
[request-duration] => 38367984198
[request-method] => GET
[request-uri] => /index.php
[query-string] =>
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/index.php
[last-request-cpu] => 0
[last-request-memory] => 0
)
[1] => Array
(
[pid] => 2803975
[state] => Idle
[start-time] => 1722198476
[start-since] => 255
[requests] => 146
[request-duration] => 70370
[request-method] => GET
[request-uri] => /keyword_compact_list_style.php
[query-string] => keyword_url_string=recreation
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/keyword_compact_list_style.php
[last-request-cpu] => 0
[last-request-memory] => 4194304
)
[2] => Array
(
[pid] => 2266367
[state] => Running
[start-time] => 1722157343
[start-since] => 41388
[requests] => 465
[request-duration] => 40694347343
[request-method] => GET
[request-uri] => /index.php
[query-string] =>
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/index.php
[last-request-cpu] => 0
[last-request-memory] => 0
)
[3] => Array
(
[pid] => 2927979
[state] => Running
[start-time] => 1722163080
[start-since] => 35651
[requests] => 119
[request-duration] => 35579263056
[request-method] => GET
[request-uri] => /index.php
[query-string] =>
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/index.php
[last-request-cpu] => 0
[last-request-memory] => 0
)
[4] => Array
(
[pid] => 2303575
[state] => Running
[start-time] => 1722157701
[start-since] => 41030
[requests] => 370
[request-duration] => 40516198463
[request-method] => GET
[request-uri] => /index.php
[query-string] =>
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/index.php
[last-request-cpu] => 0
[last-request-memory] => 0
)
[5] => Array
(
[pid] => 2581327
[state] => Running
[start-time] => 1722160109
[start-since] => 38622
[requests] => 44
[request-duration] => 38570980353
[request-method] => GET
[request-uri] => /index.php
[query-string] =>
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/index.php
[last-request-cpu] => 0
[last-request-memory] => 0
)
[6] => Array
(
[pid] => 3815068
[state] => Running
[start-time] => 1722170797
[start-since] => 27934
[requests] => 21
[request-duration] => 27911204601
[request-method] => GET
[request-uri] => /domain.php
[query-string] => domain=reecoupons.net
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/domain.php
[last-request-cpu] => 0
[last-request-memory] => 0
)
[7] => Array
(
[pid] => 2413654
[state] => Running
[start-time] => 1722158686
[start-since] => 40045
[requests] => 58
[request-duration] => 39977743199
[request-method] => GET
[request-uri] => /index.php
[query-string] =>
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/index.php
[last-request-cpu] => 0
[last-request-memory] => 0
)
[8] => Array
(
[pid] => 2757470
[state] => Idle
[start-time] => 1722198054
[start-since] => 677
[requests] => 402
[request-duration] => 53141
[request-method] => GET
[request-uri] => /domain.php
[query-string] => domain=autoskola-pernica.cz
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/domain.php
[last-request-cpu] => 0
[last-request-memory] => 2097152
)
[9] => Array
(
[pid] => 3615111
[state] => Running
[start-time] => 1722169049
[start-since] => 29682
[requests] => 81
[request-duration] => 29603208877
[request-method] => GET
[request-uri] => /index.php
[query-string] =>
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/index.php
[last-request-cpu] => 0
[last-request-memory] => 0
)
[10] => Array
(
[pid] => 3432959
[state] => Running
[start-time] => 1722167470
[start-since] => 31261
[requests] => 354
[request-duration] => 30822627032
[request-method] => GET
[request-uri] => /domain.php
[query-string] => domain=blow-job-movies.com
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/domain.php
[last-request-cpu] => 0
[last-request-memory] => 0
)
[11] => Array
(
[pid] => 3228543
[state] => Running
[start-time] => 1722165712
[start-since] => 33019
[requests] => 211
[request-duration] => 32687519764
[request-method] => GET
[request-uri] => /keyword_compact_list_style.php
[query-string] => keyword_url_string=評判
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/keyword_compact_list_style.php
[last-request-cpu] => 0
[last-request-memory] => 0
)
[12] => Array
(
[pid] => 41812
[state] => Running
[start-time] => 1722174441
[start-since] => 24290
[requests] => 393
[request-duration] => 23575447402
[request-method] => GET
[request-uri] => /index.php
[query-string] =>
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/index.php
[last-request-cpu] => 0
[last-request-memory] => 0
)
[13] => Array
(
[pid] => 2768530
[state] => Idle
[start-time] => 1722198152
[start-since] => 579
[requests] => 347
[request-duration] => 13988
[request-method] => GET
[request-uri] => /domain.php
[query-string] => domain=kiva-netz.com
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/domain.php
[last-request-cpu] => 0
[last-request-memory] => 2097152
)
[14] => Array
(
[pid] => 2825399
[state] => Idle
[start-time] => 1722198668
[start-since] => 63
[requests] => 38
[request-duration] => 34865
[request-method] => GET
[request-uri] => /domain.php
[query-string] => domain=abgqqvip.com
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/domain.php
[last-request-cpu] => 57.364117461538
[last-request-memory] => 4194304
)
[15] => Array
(
[pid] => 2824160
[state] => Idle
[start-time] => 1722198654
[start-since] => 77
[requests] => 45
[request-duration] => 30466
[request-method] => GET
[request-uri] => /domain.php
[query-string] => domain=domino78.com
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/domain.php
[last-request-cpu] => 32.823474615908
[last-request-memory] => 6291456
)
[16] => Array
(
[pid] => 2744299
[state] => Idle
[start-time] => 1722197943
[start-since] => 788
[requests] => 465
[request-duration] => 6325
[request-method] => GET
[request-uri] => /domain.php
[query-string] => domain=e-manabiya.com
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/domain.php
[last-request-cpu] => 0
[last-request-memory] => 2097152
)
[17] => Array
(
[pid] => 2744955
[state] => Idle
[start-time] => 1722197948
[start-since] => 783
[requests] => 465
[request-duration] => 53234
[request-method] => GET
[request-uri] => /domain.php
[query-string] => domain=bis.es
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/domain.php
[last-request-cpu] => 18.784986618482
[last-request-memory] => 2097152
)
[18] => Array
(
[pid] => 2752270
[state] => Running
[start-time] => 1722198011
[start-since] => 720
[requests] => 416
[request-duration] => 296
[request-method] => GET
[request-uri] => /x.php
[query-string] =>
[request-length] => 0
[user] => -
[script] => /var/www/vhosts/example.com/httpdocs/x.php
[last-request-cpu] => 0
[last-request-memory] => 0
)
)
)
Upvotes: 1
Reputation: 57685
You can use strace to show the scripts being run - and many other things - in real time. It's pretty verbose, but it can give you a good overall picture of what's going on:
# switch php-fpm7.0 for process you're using
sudo strace -f $(pidof php-fpm7.0 | sed 's/\([0-9]*\)/\-p \1/g')
The above will attach to the forked processes of php fpm. Use -p
to attach to a particular pid.
The above would get the scrip path. To get the urls, you would look at your nginx / apache access logs.
As a side note, to see the syscalls and which ones are taking longest:
sudo strace -c -f $(pidof php-fpm7.0 | sed 's/\([0-9]*\)/\-p \1/g')
Wait a while, then hit Ctr-C
Upvotes: 1
Reputation: 12935
cgi command line is more convinient:
SCRIPT_NAME=/status \
SCRIPT_FILENAME=/status \
REQUEST_METHOD=GET \
cgi-fcgi -bind -connect 127.0.0.1:9000
Upvotes: 7
Reputation: 6850
After some googling hours and browsing PHP.net bug tracking system I have found the solution. It is available since PHP 5.3.8 or 5.3.9, but doesn't seem to be documented. Based on feature request #54577, the status page supports option full
, which will display status of each worker separately. So for example the URL will be http://server.com/php-status?full
and sample output looks like:
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
Upvotes: 38
Reputation: 3536
PHP-FPM has a built in status monitor, though it's not as details as mod_status. From the php-fpm config file /etc/php-fpm.d/www.conf
(on 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
If you enable this, you can then pass the path from nginx to your socket/port for PHP-FPM and you can view the status page.
nginx.conf:
location /status {
include fastcgi_params;
fastcgi_pass unix:/var/lib/php/php-fpm.sock;
}
Upvotes: 16