Skip to content

Instantly share code, notes, and snippets.

@Jiab77
Last active September 19, 2024 09:41
Show Gist options
  • Save Jiab77/a9428050ab9bb3f17c5e33343da94fd8 to your computer and use it in GitHub Desktop.
Save Jiab77/a9428050ab9bb3f17c5e33343da94fd8 to your computer and use it in GitHub Desktop.
This gist will explain you how to enable an undocumented feature of PHP-FPM which will give a real-time performance stats.

Real-time PHP-FPM Status

This gist will explain you how to enable an undocumented feature of PHP-FPM which will give a real-time performance stats.

Everybody knows the famous phpinfo() and the page it generates, right? Then the real-time PHP-FPM status page design is very similar.

image

Some informations from the top are not displayed to avoid security issues.

Enable PHP-FPM Status

This is pretty simple to do, just run the command below.

sudo sed -i 's/;pm.status_path/pm.status_path/' /etc/php/7.0/fpm/pool.d/www.conf

Then restart the service:

sudo systemctl restart php7.0-fpm

This has been tested on PHP versions 7.0, 7.1, 7.2 and 7.3.

Edit PHP / Apache Configuration

In order to make the status page reachable, you will need to modify the PHP configuration related to Apache2.

# Do this for all installed PHP versions...
sudo nano /etc/apache2/conf-available/php7.0-fpm.conf

And add these lines:

# Enable 'status' and 'ping' page
<LocationMatch "/(ping|status)">
    SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost"
</LocationMatch>

# Enable *real-time* 'status' page
<IfModule alias_module>
    Alias /realtime-status "/usr/share/php/7.0/fpm/status.html"
</IfModule>

This file /usr/share/php/7.0/fpm/status.html is totally undocumented, I was not able to find any related information on the web.

Then restart Apache2 to apply changes:

sudo systemctl restart apache2

Make sure the PHP socket file and real-time HTML status has the correct version!

Fix the broken PHP logo (optional)

The PHP logo is broken unfortunately but I've found a way to fix it, this is just a little dirty... 😅

sudo sed -i 's|https://static.php.net/www.php.net/images/php.gif|data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHkAAABACAYAAAA+j9gsAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAD4BJREFUeNrsnXtwXFUdx8/dBGihmE21QCrQDY6oZZykon/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RQ0fkoZIr4DnRtS3ohzf1dNzTG9d0PcwMLahZO8UyKTMm38wteratSVtkplq4oWj0PcfrEinPhYg14H+hvdIwCVs1bvb6O+UBMYFGl90d0LRGLRDgoHEUwYnXDniQStocTVUwfPLaKQGA/RoWOmkvtnsaG8unK+PWMKlH5e+Lznp03N27RdO0TkxmYNZKszYBlyfI3RpjsQkmMOo8ls4Wsx1EKcEVAEvayyNoeRzsO2RI+93PNRLesGYtNpBhL4l/prlgZz5ob0mbtZVFhWC301d0EuQgAHPgS7D9hssTHKyMbRfLptF213NBDRuoaqxNA2yh2VUBDnxJ1M1yRW6gOgt2x64gqXK7ht1yOWyW1+wl7bYXvhUygQXgit4KuVDuBGzSbA2bmmtayNzpRgJOGu7XosHFChZzvrGTiUKt5UMiVsmbmtsCb3+2lZmwm3hFNsA/CiYdKyfhYx3Aws8urp8nsJM72naGCG8zYwZMecjk/WHVVRbsMwU6tBVQsWJS2sNDlrgVTO0RE/vzKQtuN2+/85k5PxlUaL75D3BZwKss+JUqSFRAO/F7Eqlkmj+2gbrgYE8rZFluu+P3pOGsyWCG/Y9/GR8exC+vYfc5flxgzRdDGsDEz/8AJsxwQcBUKPCtmKOMFJO8OKMgF8r3b3sKkAm69TN+2OZCAm5ID/g9XPypwX29ufWgudq0urrKes/8nPkxgy1bdg6z/or/SFc2mzV/xs+6HwySTmdYJp2dpaWKEregYrVfn9/B0xkD2U6+e+sOaHqImTfLrycUOIZM1hJwC3oemPXbi/y5PnsrJ136bUa8pxu69BklmANWwDRkgR1wmwVaglyi3Nz6JLQ+ZG5NxQsgNdAhmIfJN7wxgoWg9fxzPQ+c/g9YAIXgeUKCyipJO4uR/wswAOIwB/5IgxvbAAAAAElFTkSuQmCC|' /usr/share/php/7.0/fpm/status.html

Again, do this for all installed PHP versions. (no need to restart the web server)

Available status formats

The default and very well documented status page offer three different formats:

  • XML
  • JSON
  • HTML

But all of them are not refresh in real-time.

All formats, also give two different output levels:

  • normal
  • full

1. XML Format

Access URL is: http://localhost/status?xml

image

For the full output level: http://localhost/status?xml&full

image

2. JSON Format

Access URL is: http://localhost/status?json

image

For the full output level: http://localhost/status?json&full

image

3. HTML Format

Access URL is: http://localhost/status?html

image

For the full output level: http://localhost/status?html&full

image

The alias status is defined here: /etc/php/7.0/fpm/pool.d/www.conf.

Real-time status page

This is the undocumented one.

Access URL is: http://localhost/realtime-status

image

It will use the JSON output format internally to display the real-time values.

The alias realtime-status is defined here: /etc/apache2/conf-available/php7.0-fpm.conf.

Access via HTTPS protocol

At the moment you have created an SSL / TLS certificate for your testing or production domain, the standard and the real-time mode should work with both HTTP and HTTPS protocols.

References

Some references where I was able to find useful informations.

Contribute

Feel free to comment if you have any suggestions or corrections to make.

Contact

You can reach me on Twitter using: @Jiab77.

@matteocostantini
Copy link

Hi , i want to set

Enable 'status' and 'ping' page

<LocationMatch "/(ping|status)">
Require ip x.x.x.x
SetHandler "proxy:unix:/run/php/php7.0-poolname-fpm.sock|fcgi://localhost"

Enable real-time 'status' page

Alias /realtime-status "/usr/share/php/7.0/fpm/status.html"

on every apache-virtualhost-config-file.

realtime page it’s ok, but status page not! 404 response of my app in documentroot! Locationmatch not work? Any suggest?!!
thankss!!!

@Jiab77
Copy link
Author

Jiab77 commented Apr 21, 2021

Hello @matteocostantini, sorry for the late reply.

It's possible that the ping and status options are still commented in the /etc/php/7.0/fpm/pool.d/www.conf file.

Just un-comment them, restart the php-fpm service and try again with curl -I http://localhost/status or curl -I http://localhost/ping, both should return error code 200 which is expected.

Otherwise, try to look at the log files in /var/log/php-fpm or /var/log/apache2 or /var/log/httpd, you should find some useful debug information.

Hope this helps.

@huc-m
Copy link

huc-m commented Aug 27, 2021

Tanks for very very useful and complete information!

I would like to explain how thinks work. "pm.status_path" parameter gives link (like Apache Location directive) to status page. This actually is not a real file – PHP-FMP engine keeps watch and if it encounters such a link it does not search for file but sends status. The problem is how to direct this link to php – the simplest way is to add the extension “php” to it (provided that global php handler exists).

E.g. if You write

pm.status_path = “/my_server-info/php-fmp_status.php”

You get status at

https://example.com/my_server-info/php-fmp_status.php.

About “real-time status” – status.html is static html page and You may copy it where You want and open if with your favourite web browser (Firefox). To view status You have to fill “Status URL“ textbox with full link to status page, in this case:

https://example.com/my_server-info/php-fmp_status.php?json&full

If You do not want to do this every time You may change the 95-th line from

doc_url.value = location.protocol + '//' + location.host + "/status?json&full";

to (in discussed case)

doc_url.value = “https://example.com/my_server-info/php-fmp_status.php?json&full";

and enjoy.

@hayden-t
Copy link

If like me your running virtualmin, or for some other reason your listen is not using .sock but already something like listen = localhost:9001
you dont need to proxy it, just do SetHandler proxy:fcgi://localhost:xxxx Where xxxx is the port number for what virtualhost you want to show php activity for. also you will need to add pm.status_path = /status to your individual /etc/php/7.0/fpm/pool.d conf files not the global default www.conf

@omnath0
Copy link

omnath0 commented Jan 4, 2022

We also need to add ping.path = /ping in the /etc/php/7.0/fpm/pool.d/www.conf file for the Pong response.

@PaulShipley
Copy link

PaulShipley commented Dec 10, 2022

To restrict responses to localhost only change the Apache conf as follows

sudo nano /etc/apache2/conf-available/php7.4-fpm.conf

# Enable 'status' and 'ping' page
<LocationMatch "/(ping|status)">
    Require local
    SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
</LocationMatch>

# Enable *real-time* 'status' page
<IfModule alias_module>
    Alias /realtime-status "/usr/share/php/7.4/fpm/status.html"
    <Directory /usr/share/php/7.4/fpm/status.html>
       Require local
    </Directory>
</IfModule>

sudo systemctl restart apache2

This is useful for remote servers where you may not want internal status exposed to the world. Use SSH Tunnels to connect to the status pages.

Thanks

@EhsanCh
Copy link

EhsanCh commented Feb 19, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment