php fpm status page

How to Enable and Monitor PHP-FPM Status in Nginx

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.

php fpm status page. Смотреть фото php fpm status page. Смотреть картинку php fpm status page. Картинка про php fpm status page. Фото 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.

php fpm status page. Смотреть фото php fpm status page. Смотреть картинку php fpm status page. Картинка про php fpm status page. Фото php fpm status page 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.

php fpm status page. Смотреть фото php fpm status page. Смотреть картинку php fpm status page. Картинка про php fpm status page. Фото php fpm status page View PHP-FPM Status 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:

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.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

php fpm status page. Смотреть фото php fpm status page. Смотреть картинку php fpm status page. Картинка про php fpm status page. Фото php fpm status page

We are thankful for your never ending support.

Источник

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

Uncomment that line (if its commented).

Edit Nginx config

Next, in Nginx config for example.com add a location block like below:

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

Below is meaning of different values

Full PHP-FPM Status Sample

In additional to pool-level summary we have seen above, this will show extra details for per process. A sample is below:

Below is meaning of different values

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:

Example for detailed status page:

You can use json or xml format to process status page output programatically. HTML is useful when viewing detailed status report.

Источник

Jiab77 / real-time-php-fpm-status.md

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.

php fpm status page. Смотреть фото php fpm status page. Смотреть картинку php fpm status page. Картинка про php fpm status page. Фото php fpm status page

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.

Then restart the service:

Edit PHP / Apache Configuration

And add these lines:

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:

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. 😅

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:

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

All formats, also give two different output levels:

php fpm status page. Смотреть фото php fpm status page. Смотреть картинку php fpm status page. Картинка про php fpm status page. Фото php fpm status page

php fpm status page. Смотреть фото php fpm status page. Смотреть картинку php fpm status page. Картинка про php fpm status page. Фото php fpm status page

php fpm status page. Смотреть фото php fpm status page. Смотреть картинку php fpm status page. Картинка про php fpm status page. Фото php fpm status page

php fpm status page. Смотреть фото php fpm status page. Смотреть картинку php fpm status page. Картинка про php fpm status page. Фото php fpm status page

php fpm status page. Смотреть фото php fpm status page. Смотреть картинку php fpm status page. Картинка про php fpm status page. Фото php fpm status page

php fpm status page. Смотреть фото php fpm status page. Смотреть картинку php fpm status page. Картинка про php fpm status page. Фото php fpm status page

Real-time status page

This is the undocumented one.

php fpm status page. Смотреть фото php fpm status page. Смотреть картинку php fpm status page. Картинка про php fpm status page. Фото php fpm status page

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

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.

Some references where I was able to find useful informations.

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

You can reach me on Twitter using: @Jiab77.

This comment has been minimized.

Copy link Quote reply

matteocostantini commented Apr 3, 2021

Enable ‘status’ and ‘ping’ page

Require ip x.x.x.x
SetHandler «proxy:unix:/run/php/php7.0-poolname-fpm.sock|fcgi://localhost»

Enable real-time ‘status’ page

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.

This comment has been minimized.

Copy link Quote reply

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.

This comment has been minimized.

Copy link Quote reply

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).

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:

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

Источник

Malasuk

A simple collection of information

Categories

PHP-FPM status page

You can enable a php-fpm status page that will provide details about php-fpm’s health. This can also be useful for scripts to check the status and monitor for issues. Setup is very easy and can be configured by uncommenting (or adding) an option in the php-fpm pool configuration file and ensuring the web server allows the traffic.

The default php-fpm pool configuration file provided on package installation can be found at the following locations. Keep in mind if you are running an Ubuntu based system that the path could be different depending on the version of php you are running. Just substitute the version number for what you are running.

In the default configuration, we want to uncomment the «pm.status_path» value. (See the bold text below) I have included the default comments as it provides great information on what the status page can do.

Once you have uncommented the pm.status_path, lets validate the syntax is fine before we reload the service

Now reload the php-fpm service to make the change active

The status page is now available to the default php-fpm pool. If you have multiple php-fpm pools, you may need to add the «pm.status_path = /status» directive to the pool you want the status of.

Now, that php-fpm is configured to display its status, we need to configure the web server to allow the request.

Nginx

In the Nginx server block for your website, you need to allow the request. We can use the server block to limit traffic to only trusted IP address since the information provided should be considered sensitive.

Just make sure that the fastcgi_pass directive points to the port or socket that your application is talking to. If your not sure what to use, check your Nginx configuration file your editing for the fastcgi_pass directive in your php location block.

With the location block added, check the syntax and reload Nginx

Verify

Now that we have configured php-fpm and the web server to allow the /status request, you can view the status in a browser via http://[IP or Domain]/status?full or via the curl command.

Review the comments in the configuration that I provided above for all the options you can pass to the status page. You can get a simple overview with just /status or more information with /status?full

You can also get the output in different formats such as json or html to integrate into your monitoring or automation systems.

The following is example output of the php-fpm status.

We can see that the php-fpm status page is now working. You can use this information for your monitoring systems or automation systems to take action based on the status of the php-fpm pools.

Practical Monitoring

So, now that we are monitoring our php-fpm processes, what should we look for? How do we know we have a problem?

Lets focus on the holistic view and only pass the /status. We can review the items in bold to know when a problem has happened, or is about to happen

max children reached

For basic monitoring, you should keep an eye on «max children reached». The «max children reached» value will increment whenever the process limit has been reached and php-fpm is unable to create more children to handle requests. (This value only matters when php-fpm is operating in dynamic and/or ondemand mode, with dynamic being the default mode.)

If «max children reached» is anything above 0, that means you had requests to php-fpm queuing and the user had to wait for a process to be free to be handeled. This could indicate a traffic spike that is overloading your server, or perhaps a database issue that is slowing the response of requests and impacting users. Moral of this value, is you want to know when it is anything above 0.

You could create a URL monitor that checks for that value and triggers an alert or email if the value is above 0. If this alert triggers, you know you are currently encountering a problem.

idle processes

What if you want to know before a problem happens? This requires you know a little more about your php-fpm configuration to get right. Php-fpm can be run in multiple different modes: static, dynamic, or ondemand. Dynamic is the default so lets talk about what this value means when you are set to dynamic.

In your php-fpm configuration you have a number of values set to control the number of processes that are allowed to spawn and handle requests

Based on those values that we have set, we could trigger an action based on the number of idle processes available. So lets say for our example we have the following php-fpm pool configuration

We can see that at maximum, we may have 20 php-fpm processes (max_children). When the pool is created it will have 5 idle processes (start_servers), we want to maintain at least 5 idle processes (min_spare_servers), and we don’t want more than 10 idle processes (max_spare_servers).

Because php-fpm is running in dynamic mode, it will create more processes as needed and tear them down when they are not needed. Since we have a maximum of 20 processes and a minimum of 5 idle processes, we know we are approaching capacity when we get lower than 5 idle processes.

If we want to know before a problem is about to happen, we could monitor the «idle processes» in the status and trigger a warning when there are 2 or less processes idle. Since we know php-fpm wants 5 idle processes, the only reason it would not create more processes is if it is approaching the max_children value.

If you have automation in place, when ‘»idle processes» is low, it would be a good time to spin up more web servers or add additional capacity. You could use this same value to scale back down automatically.

If you have a dedicated web server running just Apache/Nginx and php-fpm, you may want to configure php-fpm to run in a static mode. There are some performance gains in static mode as the overhead in creating and destroying processes is mostly removed. Your ‘idle processes’ trigger is pretty easy to calculate in static mode. If your running php-fpm in static mode and have 50 children processes, you know your close to capacity once you have less than 5 processes idle.

listen queue

The listen queue is another value you can monitor to find problems before they happen. The listen queue value is the number of requests pending connections to the pool. I mention this value after we talked about ‘idle processes’ because once this value is hit, your processes are already full. On a website with low to medium traffic, monitoring the idle processes may be ideal, however for larger sites, its not uncommon for all the processes to be in use and there be a backlog of connections waiting to be processed by php-fpm. The total number of connections that can be backlogged is configured in the pool via the listen.backlog directive, which defaults to 511

If your php-fpm processes are typically full and active, you can instead trigger monitoring or automation based on the number of connections backlogged. For example you may want to build additional capacity when there is more than 50 connections backlogged.

Conclusion

The php-fpm status page can be used to monitor your application performance and find issues before they happen. It can also be tied into automation to automatically scale up or down your application tier depending on performance. Should you enable the status page however, please ensure the page is locked down to trusted IP addresses or password protected, as it does expose information about your application that can be used to construct malicious requests.

I may circle back to this article and add more monitoring/automation examples, but for now I hope this information has helped you. Please reach out with any comments or questions.

Источник

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

Uncomment that line (if its commented).

Edit Nginx config

Next, in Nginx config for example.com add a location block like below:

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

Below is meaning of different values

Full PHP-FPM Status Sample

In additional to pool-level summary we have seen above, this will show extra details for per process. A sample is below:

Below is meaning of different values

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:

Example for detailed status page:

You can use json or xml format to process status page output programatically. HTML is useful when viewing detailed status report.

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *