Dump the code

Using the status page for insights

Created 7 months ago
Posted By admin
5min read
PHP-FPM's status page provides valuable insights into the current state of PHP-FPM and its pools. To utilize the status page for insights, follow these steps:

1. Enable the status page:
Edit your PHP-FPM pool configuration file (e.g., /etc/php/8.2/fpm/pool.d/www.conf) and add or modify the pm.status_path directive:

pm.status_path = /status
This sets the URL path for the status page to /status.

sudo systemctl restart php8.2-fpm  # Adjust the version number

2. Add location in web server
When you add the pm.status_path configuration in your PHP-FPM pool configuration, you need to ensure that your web server (in this case, Nginx) is configured to handle requests to that path.

In your Nginx configuration, you have to add a location block for the /status path. Here's an example of how you can do this in your Nginx configuration file:

server {
    # ... other server configurations ...

    location /status {
        include fastcgi_params;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        allow 127.0.0.1;
        deny all;
        fastcgi_param PHP_VALUE "pm.status_path=/status";
    }

    # ... other server configurations ...
}

In this example:
  • The location /status block is added to handle requests to the /status path.
  • The fastcgi_pass directive points to the PHP-FPM socket. Adjust the path based on your PHP version and configuration.
  • The fastcgi_param directives set the necessary parameters, including pm.status_path.
  • Access to the /status path is restricted to localhost for security reasons, using the allow and deny directives.

After making changes to your Nginx configuration, remember to reload or restart Nginx for the changes to take effect:

sudo systemctl reload nginx

3. Access the status page:
Open a web browser and navigate to the status page:

http://your-server/status
Replace your-server with the actual domain or IP address of your server. The status page provides various sections with insights into the PHP-FPM status.

4. Key Insights from the status page:
a. Summary information:
   - pool: Shows the name of the pool.
   - process manager: Displays the process manager strategy (e.g., dynamic or static).
   - start time: Indicates when PHP-FPM was started.

b. Requests:
   - accepted conn: Total number of accepted connections.
   - listen queue: The length of the pending connections queue.

c. Processes:
   - processes: Number of active processes.
   - max active processes: Maximum number of active processes.
   - max children reached: Number of times the process limit has been reached.

d. Performance:
   - slow requests: Number of requests that exceeded the `request_slowlog_timeout` setting.

e. Memory:
   - free memory: Free memory available for PHP-FPM.
   - allocated memory: Total memory allocated to PHP-FPM.

f. CPU:
   - cpu: CPU usage information.

g. Requests details:
   - request method: HTTP method of the current request.
   - request duration: Duration of the request.
   - request slowest: Longest request execution time.
   - request method: HTTP method of the current request.
   - request URI: URI of the current request.

5. Interpreting the information:
- Accepted connections and listen Queue:
High values may indicate a surge in traffic or potential performance issues.

- Processes:
Monitor the number of active processes. If the value is frequently reaching the maximum allowed, consider adjusting pm.max_children.

- Performance:
Keep an eye on the number of slow requests. Frequent slow requests may indicate performance bottlenecks.

- Memory and CPU:
Monitor memory and CPU usage to ensure that PHP-FPM is not exhausting system resources.

6. Automating insights:
You can automate the retrieval of insights from the status page using tools like cURL or script solutions. For example, using cURL:

curl http://your-server/status
Consider parsing and analyzing the output for specific metrics based on your monitoring needs.

By regularly checking the status page and interpreting the information provided, you can proactively address issues, optimize performance, and ensure the smooth operation of your PHP-FPM setup. Adjust the frequency of checks based on your monitoring requirements.
Topics

Mastering Nginx

27 articles

Bash script

2 articles

Crontab

2 articles