Enable and Monitor PHP-FPM Status in Nginx

Linux

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation that comes with a number of extra features useful for websites of any size, particularly sites that receive high traffic.

It is commonly used in the LEMP (Linux Nginx MySQL/MariaDB PHP) stack; Nginx uses PHP FastCGI for serving dynamic HTTP content on a network. It is being used to serve millions of PHP requests for hundreds of websites on web servers on the internet.

One of the useful features of php-fpm is the built-in status page, which can help you monitor its health. In this article, we will show how to enable the PHP-FPM status page on Linux.

How to Enable PHP-FPM Status Page in Linux

First open the php-fpm configuration file and enable the status page as shown.

Inside this file, find and uncomment the variable pm.status_path = /status as shown in the screenshot.

Enable PHP-FPM Status Page

Enable PHP-FPM Status Page

Save the changes and exit the file.

Next, check that the PHP-FPM configuration file for any errors by running the command below.

Check PHP-FPM Configuration File

Check PHP-FPM Configuration File

Then restart the PHP-FPM service to apply the recent changes.

Next, edit your default server block (virtual host) configuration file and add the location block below in it. For instance on the test system, the default server block’s config file is /etc/nginx/conf.d/default.conf, for the site test.lab.

Here is the location block to be added. In this config, we have only allowed access to PHP-FPM process status within the localhost using the directive allow 127.0.0.1 for security reasons.

Save the file and close it.

Then restart the Nginx server to apply the above changes.

Now open a browser and type the URL http://test.lab/status to view your PHP-FPM process status.

View PHP-FPM Status Page

View PHP-FPM Status Page

Alternatively, use the curl program as follows, where the -L flag specifies the location of the page.

By default, the status page only prints out a summary or short status. To view status for each pool process, pass “full” in the query string, for instance:

You can define the output format (JSON, HTML or XML) as shown.

Below are the values returned in the php-fpm full status, for each process:

  • pid – PID of the process.
  • state process status (idle, running, etc.).
  • start time – date and time the process has started.
  • start since – number of seconds since the process has started.
  • requests – number of requests the process has served.
  • request duration – duration in µs of the requests.
  • request method – request method (GET, POST, etc.).
  • request URI – request URI with the query string.
  • content length – content length of the request (only with POST).
  • user – user (PHP_AUTH_USER) (or ‘-‘ if not set).
  • script – main script called (or ‘-‘ if not set).
  • last request cpu – %cpu the last request consumed (note that it’s always 0 if the process is not in Idle state).
  • last request memory – max amount of memory the last request consumed (it’s always 0 if the process is not in Idle state).

That’s it for now! In this article, we have explained how to enable the php-fpm status page under Nginx web server. Use the feedback form below to share your thoughts with us.

Source

Share: