How to display PHP-FPM pool information using command-line utilities

Display PHP-FPM (FastCGI Process Manager) pool information using command-line utilities like curl or cgi-fcgi.

Enable FPM status page for a specific pool

Edit PHP-FPM pool configuration file to define status page URI.

$ sudo vim /etc/php/7.0/fpm/pool.d/www.conf
[...]
pm.status_path = /status
[...]

By default the status page is not enabled as URI is not defined.

Reload PHP-FPM service to apply the configuration change.

$ sudo systemctl reload php7.0-fpm

Serve PHP-FPM status page for a specific pool

Use the following NGINX configuration snippet to ensure that status page is available only on local machine.

  location ~ ^/status$ {
    allow 127.0.0.1/32;
    deny all;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
  }

You can just deny all requests which is a better solution or use basic authentication to restict access.

Use curl utility to access status page

Display PHP-FPM pool information.

$ curl -4k https://localhost/status
pool:                 www
process manager:      ondemand
start time:           13/Aug/2018:21:18:30 +0000
start since:          315
accepted conn:        96
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       1
active processes:     1
total processes:      2
max active processes: 7
max children reached: 0
slow requests:        0

Display full PHP-FPM pool information.

$ curl -4k https://localhost/status?full
pool:                 www
process manager:      ondemand
start time:           13/Aug/2018:21:18:30 +0000
start since:          354
accepted conn:        100
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       0
active processes:     1
total processes:      1
max active processes: 7
max children reached: 0
slow requests:        0

************************
pid:                  20375
state:                Running
start time:           13/Aug/2018:21:24:19 +0000
start since:          5
requests:             2
request duration:     267
request method:       GET
request URI:          /status?full
content length:       0
user:                 -
script:               -
last request cpu:     0.00
last request memory:  0

Display PHP-FPM pool information using JSON format.

$ curl -4k https://localhost/status?json
{"pool":"www","process manager":"ondemand","start time":1534195110,"start since":331,"accepted conn":98,"listen queue":0,"max listen queue":0,"listen queue len":0,"idle processes":0,"active processes":1,"total processes":1,"max active processes":7,"max children reached":0,"slow requests":0}

Display full PHP-FPM pool information using XML format.

$ curl -4k "https://localhost/status?full&xml"
<?xml version="1.0" ?>
<status>
<pool>www</pool>
<process-manager>ondemand</process-manager>
<start-time>1534195110</start-time>
<start-since>407</start-since>
<accepted-conn>107</accepted-conn>
<listen-queue>0</listen-queue>
<max-listen-queue>0</max-listen-queue>
<listen-queue-len>0</listen-queue-len>
<idle-processes>0</idle-processes>
<active-processes>1</active-processes>
<total-processes>1</total-processes>
<max-active-processes>7</max-active-processes>
<max-children-reached>0</max-children-reached>
<slow-requests>0</slow-requests>
<processes>
<process><pid>20383</pid><state>Running</state><start-time>1534195492</start-time><start-since>25</start-since><requests>6</requests><request-duration>261</request-duration><request-method>GET</request-method><request-uri>/status?full&amp;xml</request-uri><content-length>0</content-length><user>-</user><script>-</script><last-request-cpu>0.00</last-request-cpu><last-request-memory>0</last-request-memory></process>
</processes>
</status>

Use simple CGI/1.1 program to communicate with an already-running FastCGI server

Install shared FastCGI library that includes a cgi-fcgi utility.

$ sudo apt-get install -y libfcgi0ldbl
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libfcgi-bin
The following NEW packages will be installed:
  libfcgi-bin libfcgi0ldbl
0 upgraded, 2 newly installed, 0 to remove and 4 not upgraded.
Need to get 162 kB of archives.
After this operation, 483 kB of additional disk space will be used.
Get:1 http://ftp.icm.edu.pl/pub/Linux/distributions/raspbian/raspbian stretch/main armhf libfcgi0ldbl armhf 2.4.0-8.4 [151 kB]
Get:2 http://ftp.icm.edu.pl/pub/Linux/distributions/raspbian/raspbian stretch/main armhf libfcgi-bin
armhf 2.4.0-8.4 [11.2 kB]
Fetched 162 kB in 0s (266 kB/s)
Selecting previously unselected package libfcgi0ldbl:armhf.
(Reading database ... 38762 files and directories currently installed.)
Preparing to unpack .../libfcgi0ldbl_2.4.0-8.4_armhf.deb ...
Unpacking libfcgi0ldbl:armhf (2.4.0-8.4) ...
Selecting previously unselected package libfcgi-bin.
Preparing to unpack .../libfcgi-bin_2.4.0-8.4_armhf.deb ...
Unpacking libfcgi-bin (2.4.0-8.4) ...
Setting up libfcgi0ldbl:armhf (2.4.0-8.4) ...
Processing triggers for libc-bin (2.24-11+deb9u3) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up libfcgi-bin (2.4.0-8.4) ...

Display PHP-FPM pool information.

$ sudo -u www-data bash -c "export SCRIPT_NAME=/status; export SCRIPT_FILENAME=/status; export REQUEST_METHOD=GET; cgi-fcgi -bind -connect /var/run/php/php7.0-fpm.sock"
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache, no-store, must-revalidate, max-age=0
Content-type: text/plain;charset=UTF-8

pool:                 www
process manager:      ondemand
start time:           13/Aug/2018:21:18:30 +0000
start since:          879
accepted conn:        161
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       0
active processes:     6
total processes:      6
max active processes: 7
max children reached: 0
slow requests:        0

Display full PHP-FPM pool information.

$ sudo -u www-data bash -c "export SCRIPT_NAME=/status; export SCRIPT_FILENAME=/status; export QUERY_STRING=full; export REQUEST_METHOD=GET; cgi-fcgi -bind -connect /var/run/php/php7.0-fpm.sock"
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache, no-store, must-revalidate, max-age=0
Content-type: text/plain;charset=UTF-8

pool:                 www
process manager:      ondemand
start time:           13/Aug/2018:21:18:30 +0000
start since:          982
accepted conn:        203
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       0
active processes:     1
total processes:      1
max active processes: 7
max children reached: 0
slow requests:        0

************************
pid:                  21048
state:                Running
start time:           13/Aug/2018:21:34:50 +0000
start since:          2
requests:             2
request duration:     484
request method:       GET
request URI:          /status?full
content length:       0
user:                 -
script:               -
last request cpu:     0.00
last request memory:  0

Additional information

FastCGI Specification