Nginx – Enable PHP-FPM Status Page

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 {
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;
}

location = /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.  Trying ondemand 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 requestsEnable 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.

41 responses to “Nginx – Enable PHP-FPM Status Page”

      • I’m also getting a 502 Bad Gateway error.

        This is the output from the error.log file:

        2014/01/09 08:09:52 [error] 7497#0: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: magento, request: “GET /status HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “www.mydomain.co.uk”

  1. No problem getting it to work. Now that I/we can see the stats, what exactly are we on the lookout for?

    While the definitions are given for each term, it is not exactly clear what good numbers are and what bad numbers are, nor what to do should we encounter bad numbers. Like if ‘x’ term = ‘xyz’ then increase this value etc..

  2. Hello,

    After following the above instructions, I receive the following error upon restarting nginx:

    nginx: [emerg] no port in upstream “php” in /etc/nginx/nginx.conf:72

    I’m running this on Arch Linux ARM. I tried replacing “php” with “127.0.0.1:9000” in the offending line, which eliminated the error; however, the resulting php-fpm status page was simply blank. (I tried “127.0.0.1:9000” because it’s used in another “location” block statement, “fastcgi_pass 127.0.0.1:9000;“).

    Any ideas how to fix this?

    buzz

      • Hello Rahul,

        Line 72 of the /etc/nginx/nginx.conf file is:

        fastcgi_pass php;

        This is the line from your instructions above. The “php” element in this statement is causing problems. Why?

        buzz

  3. Hello, slow requests doesn’t appear in status after I turn on slow log:

    slowlog = /var/log/php5/slow.log

    request_slowlog_timeout = 10s

    Probably I need something else to do, to se it ?

    • It could be because every request is getting completed in less than 10s.

      Try setting a value to 1s. If that doesn’t work, then there could be an issue with config.

      Also check if file /var/log/php5/slow.log exists physically on disk.

  4. Hi, thanks for this neat tip. I was not aware if this neat PHP5-FPM feature.

    Small remark: There seem to be missing some trailing “;” signs in the nginx site conf code. Plus it might be helpful to mention the use of “unix:/var/run/php5-fpm.sock” for those that followed other tutorials on this site 🙂

      • If your goal is to check if PHP-FPM is replying to request only, you can open /ping path and see if it returns pong.

        It may sound funny but if you have external process monitoring your FPM, such a short reply can reduce bandwidth. Though I think, in practise /status output will also fit in single packet. May be FPM need to do some calculation to return /status but for /ping/ it returns a predefined string only.

    • I updated article for missing ;.

      I will update cross-check all tutorials for unix:/var/run/php5-fpm.sock.

      Our internal convention is to have upstream { } block for PHP backend so we keep adding/removing FPM pools and sometimes use mix of tcp/ip and unix-based sockets.

      I will try to stick to one method and update all articles soon.

  5. Hi ,
    ‘full’ option is not working. I am just getting the basic stats.Any ideas why?
    Here is my location section

    location ~ ^/(fpmstatus|ping)$ {
       access_log off;
       allow 127.0.0.1;
       allow  ;
       deny all;
       include        /usr/local/nginx/conf/fastcgi_params;
       fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
       fastcgi_pass 127.0.0.1:9000;
    }

    Thanks.

  6. Thanks for the set of good instructions. It also got the PHP-FPM ping/pong test working so that I could set up an alert on Copperegg.com to warn if it goes down.

  7. Hi, i did everything as this tutorial but when i request /status i get just a BLANK page.
    I have restarted all services and the logs of nginx and php-fpm doesn’t contain anything related … don’t know what to do

    • Try removing access_log off; and see if your hits to /status are reaching nginx.

      Most likely it could be mismatch with pm.status_path = /status in /etc/php5/fpm/pool.d/www.conf

    • Try this one

      location ~ ^/(status|ping|apc_info.php)$ {
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_pass backend;
      allow 127.0.0.1;
      deny all;
      }

  8. For those who are getting a gateway error upon using this guide, this is due to PHP5-FPM unable to create the log files needed, so make sure that you create the folders and files for your logs as per http://www.conf and php5-fpm.conf before you complete this guide.

    For example for the following paramters:

    access.log = /var/log/php5-fpm/access.log in http://www.conf
    slowlog = /var/log/php5-fpm/slow.log in http://www.conf
    error_log = /var/log/php5-fpm/daemon.log in php5-fpm.log

    You would need to create the folders yourself for /var/log/php5-fpm/ as the default parameters link to a non-existing path for some reason on ubuntu.

    • You cannot get php restart error after following this article which is related to log files.

      This article doesn’t change any log file path so how can it complain about folder creation?

      Looks like you have mixed instructions from multiple sources.

      • That’s what I thought, but the default path log/php5-fpm.log was inaccessible, and the error the guys are complaining about in the comments disappeared after I fixed it to a path that exists.

        • That path has nothing to do with this article.

          Anyway, default `log/php5-fpm` refers to `/var/log` which is created by OS. I did not asked to change log path in this article.

          Only line which is sensitive in this article is: `fastcgi_pass 127.0.0.1:9000;`

          If somebody has FPM listening on other port/socket, they need to change this line.