PHP-FPM has a very useful built-in status page.

You can access it over web and also write scripts to monitor your PHP-FPM sites health remotely.

Enabling PHP-FPM Status Page

Edit PHP-FPM Config

In file /etc/php5/fpm/pool.d/www.conf, find pm.status_path variable.

vim +/pm.status_path /etc/php5/fpm/pool.d/www.conf

Uncomment that line (if its commented).

Default value is /status. You can change it to something else. May be you can add pool-prefix if you are running multiple PHP pools.

pm.status_path = /status

Edit Nginx config

Next, in Nginx config for example.com add a location block like below:

location ~ ^/(status|ping)$ {
     access_log off;
     allow 127.0.0.1;
     allow 1.2.3.4#your-ip;
     deny all;
     include fastcgi_params;
     fastcgi_pass 127.0.0.1:9000;
}

Do not forget to replace your IP address. For security reasons, its better to keep your PHP-FPM status page private.

Reload PHP-FPM and Nginx config for changes to take effect.

PHP-FPM Status Sample

Default PHP-FPM Status Sample

Now, open http://example.com/status in browser to see summarised stats like below

pool:                 www
process manager:      dynamic
start time:           17/May/2013:13:54:02 +0530
start since:          886617
accepted conn:        1619617
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       28
active processes:     2
total processes:      30
max active processes: 31
max children reached: 0
slow requests:        0

Below is meaning of different values

  • pool – the name of the pool. Mostly it will be www.

  • process manager – possible values static, dynamic or ondemand. We never use static.  Tryingondemand is on todo list.

  • start time – the date and time FPM has started or reloaded. Reloading PHP-FPM (service php5-fpm reload) reset this value.

  • start since – number of seconds since FPM has started

  • accepted conn – the number of request accepted by the pool

  • listen queue – the number of request in the queue of pending connections. If this number is non-zero, then you better increase number of process FPM can spawn.

  • max listen queue – the maximum number of requests in the queue of pending connections since FPM has started

  • listen queue len – the size of the socket queue of pending connections

  • idle processes – the number of idle processes

  • active processes – the number of active processes

  • total processes – the number of idle + active processes

  • max active processes – the maximum number of active processes since FPM has started

  • max children reached – number of times, the process limit has been reached, when pm tries to start more children. If that value is not zero, then you may need to increase max process limit for your PHP-FPM pool. Like this, you can find other useful information to tweak your pool better way.

  • slow requests – Enable php-fpm slow-log before you consider this. If this value is non-zero you may have slow php processes. Poorly written mysql queries are generally culprit.

Full PHP-FPM Status Sample

If you want detailed stats, you can pass argument ?fullto status page URL. It will become http://example.com/status?full

In additional to pool-level summary we have seen above, this will show extra details for per process. A sample is below:

pid:                  1419692
state:                Idle
start time:           27/May/2013:20:06:12 +0530
start since:          287
requests:             32
request duration:     188927
request method:       GET
request URI:          /feed.php?uid=12997446135571490564
content length:       0
user:                 -
script:               /var/www/example.com/htdocs/feed.php
last request cpu:     5.29
last request memory:  524288

Below is meaning of different values

  • pid – the PID of the process. You can use this PID to kill a long running process.

  • state – the state of the process (Idle, Running, …)

  • start time – the date and time the process has started

  • start since – the number of seconds since the process has started

  • requests – the number of requests the process has served

  • request duration – the duration in μs of the requests

  • request method – the request method (GET, POST, …)

  • request URI – the request URI with the query string

  • content length – the content length of the request (only with POST)

  • user – the user (PHP_AUTH_USER) (or ‘-‘ if not set)

  • script – the main PHP script called (or ‘-‘ if not set)

  • last request cpu – the %cpu the last request consumed. it’s always 0 if the process is not in Idle state because CPU calculation is done when the request processing has terminated

  • last request memorythe max amount of memory the last request consumed. it’s always 0 if the process is not in Idle state because memory calculation is done when the request processing has terminated

Note: If the process is in Idle state, then informations are related to the last request the process has served. Otherwise informations are related to the current request being served.

PHP-FPM Status Page Output formats

By default the status page output is formatted as text/plain. Passing either ‘html’, ‘xml’ or ‘json’ in the query string will return the corresponding output syntax.

Examples for summary status page:

  • http://example.com/status

  • http://example.com/status?json

  • http://example.com/status?html

  • http://example.com/status?xml

Example for detailed status page:

  • http://example.com/status?full

  • http://example.com/status?json&full

  • http://example.com/status?html&full

  • http://example.com/status?xml&full

You can use json or xml format to process status page output programatically. HTML is useful when viewing detailed status report.