PHP-FPM Monitoring

PHP-FPM (FastCGI Process Manager) is an alternative implementation of PHP FastCGI that comes with several additional features that are useful for websites of all sizes, especially those that receive high traffic.

It is commonly utilized in the LEMP (Linux Nginx MySQL/MariaDB PHP) stack; Nginx employs PHP FastCGI to serve dynamic HTTP content on a network. It is responsible for handling millions of PHP requests for hundreds of websites on internet servers.

Enabling PHP-FPM Status Page in Linux

To begin, open the php-fpm configuration file and enable the status page as follows:

$ sudo vim /etc/php-fpm.d/www.conf


$ sudo vim /etc/php/7.2/fpm/pool.d/www.conf #for PHP versions 5.6, 7.0, 7.1

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

Enable PHP-FPM Status Page

Save the changes and exit the file.

Next, check the PHP-FPM configuration file for any errors by running the following command:

$ sudo php-fpm -t


$ sudo php7.2-fpm -t

Afterward, restart the PHP-FPM service to apply the recent changes:

$ sudo systemctl restart php-fpm


$ sudo systemctl restart php7.2-fpm

Now, edit the default server block (virtual host) configuration file and add the following location block to it. For example, on the test system, the default server block’s config file is located at /etc/nginx/conf.d/default.conf for the site test.lab:

$ sudo vim /etc/nginx/conf.d/default.conf

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

location ~ ^/(status|ping)$ {
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_pass unix:/var/run/php7.2-fpm.sock;

Save the file and close it.

See also  Programs for PHP in Connecticut

Then, restart the Nginx server to apply the above changes:

$ sudo systemctl restart nginx

Finally, open a browser and enter the URL http://test.lab/status to view the PHP-FPM process status.

View PHP-FPM Status Page

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

$ curl -L http://test.lab/status

By default, the status page only displays a summary or short status. To view the status for each pool process, append "full" to the query string, for instance:

You can also 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 started.
  • start since: Number of seconds since the process 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 the Idle state).
  • last request memory: Max amount of memory the last request consumed (it’s always 0 if the process is not in the Idle state).

That’s it for now! In this article, we have explained how to enable the php-fpm status page under the Nginx web server. If you have any thoughts or feedback, please share them with us via the ProgramMatek feedback form below.

See also  PHP for Frontend Development