How to Enable and Monitor PHP-FPM Status in Nginx

shell
Description

PHP-FPM (FastCGI Process Manager) is a popular solution for serving dynamic PHP content via the Apache and NGINX web servers. It's quite performant out of the box, however occasions do arise when you'll need to dig into the configuration to gain a deeper understanding of how the PHP processes are handling your application scripts. This is admittedly a mix of science and art, however there is one simple feature you can enable to immediately gain greater insights into metrics such as active processes, slow requests, and the number of times the allocated number of PHP processes have reached capacity. When enabled, you'll be able to go to a URL and view output which looks like this:

pool:                 www
process manager:      dynamic
start time:           10/Aug/2020:20:33:42 +0000
start since:          4565539
accepted conn:        238803
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       9
active processes:     1
total processes:      10
max active processes: 7
max children reached: 1
slow requests:        8

To configure the status page, open your PHP-FPM  www.conf file and find pm.status_path:

pm.status_path = /fpm-status

Uncomment the line, and change the value to some suitable URI, making sure to leave the forward slash in place. Save the changes, then open nginx.conf and add this block:

location = /fpm-status {
  access_log off;
  fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
}

If PHP-FPM is configured to instead listen on a port, change the fastcgi_pass variable accordingly. Once complete, restart the NGINX and PHP-FPM daemons and navigate to the designated URI to view the status page.

Need API Advice?

Our team has advised thousands of companies around the world on API projects. Go to market faster by talking to the API experts.

jeanie

Ready to get started?