PHP-FPM Status + Cron: Catch Pool Saturation Before Users Do
The PHP-FPM status endpoint has been there all along. A five-line cron job reading it has saved me more incidents than any APM dashboard.
Most PHP developers have never looked at their FPM status page. It ships with every PHP-FPM install, it costs nothing to enable, and it will tell you your pool is drowning before a single user files a support ticket. I've been using a dead-simple cron-based poller for years and it has caught saturation events on client servers a dozen times.
What the Status Endpoint Actually Tells You
PHP-FPM manages a pool of worker processes. When a request comes in, it hands it to an idle worker. When all workers are busy, the request queues. When the queue fills, connections get refused. That progression - idle to busy to queued to refused - is the whole story of FPM saturation, and the status endpoint exposes every number in that chain.
The problem it solves is deceptively simple: PHP itself has no built-in way to tell you "I am running out of workers." Your app stays silent. Nginx returns 502s. Users see a spinner. Meanwhile you're SSHing in and running ps aux | grep php trying to count processes by hand.
The status endpoint gives you a live feed of pool health in a machine-readable format. You just have to ask for it.
Enabling It
In your pool config - usually /etc/php/8.x/fpm/pool.d/www.conf - uncomment or add:
pm.status_path = /fpm-status
Then in Nginx, add a location block that only allows local access:
location /fpm-status {
access_log off;
allow 127.0.0.1;
deny all;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Reload both services and hit http://127.0.0.1/fpm-status?json from the server. You'll get something like:
{
"pool": "www",
"process manager": "dynamic",
"start time": 1718000000,
"start since": 86400,
"accepted conn": 2847193,
"listen queue": 0,
"max listen queue": 12,
"listen queue len": 128,
"idle processes": 4,
"active processes": 11,
"total processes": 15,
"max active processes": 18,
"max children reached": 3,
"slow requests": 0
}
That max children reached counter is the one that keeps me up at night. Any value above zero means FPM hit its ceiling and had to queue requests. It's a ratchet - it never goes down - so a non-zero reading tells you saturation has happened at least once since the last restart.
The Cron Poller
Here's the script I actually deploy. It lives at /usr/local/bin/fpm-monitor and runs every minute.
#!/usr/bin/env php
<?php
/**
* FPM pool saturation monitor.
* Writes metrics to a log file and sends an alert when thresholds are breached.
* Run every minute via cron.
*/
define('STATUS_URL', 'http://127.0.0.1/fpm-status?json');
define('LOG_FILE', '/var/log/fpm-monitor.log');
define('ALERT_EMAIL', 'ops@example.com');
// Thresholds - tune these for your pool size.
define('IDLE_MIN', 2); // alert if fewer than this many idle workers
define('QUEUE_MAX', 5); // alert if listen queue exceeds this
define('ACTIVE_PCT_WARN', 80); // alert if active/total exceeds this percent
$ctx = stream_context_create(['http' => ['timeout' => 3]]);
$raw = @file_get_contents(STATUS_URL, false, $ctx);
if ($raw === false) {
alert('FPM status endpoint unreachable - is FPM running?');
exit(1);
}
$data = json_decode($raw, true);
if (!$data) {
alert('FPM status returned unparseable response');
exit(1);
}
$idle = (int) $data['idle processes'];
$active = (int) $data['active processes'];
$total = (int) $data['total processes'];
$queue = (int) $data['listen queue'];
$maxQueue = (int) $data['max listen queue'];
$maxReached = (int) $data['max children reached'];
$slowReqs = (int) $data['slow requests'];
$activePct = $total > 0 ? round(($active / $total) * 100) : 0;
$logLine = sprintf(
'[%s] pool=%s idle=%d active=%d total=%d queue=%d max_queue=%d max_reached=%d slow=%d active_pct=%d%%',
date('Y-m-d H:i:s'),
$data['pool'],
$idle,
$active,
$total,
$queue,
$maxQueue,
$maxReached,
$slowReqs,
$activePct
);
file_put_contents(LOG_FILE, $logLine . PHP_EOL, FILE_APPEND | LOCK_EX);
// Check thresholds.
$problems = [];
if ($idle < IDLE_MIN) {
$problems[] = "Only {$idle} idle workers (min: " . IDLE_MIN . ")";
}
if ($queue > QUEUE_MAX) {
$problems[] = "Listen queue at {$queue} (max: " . QUEUE_MAX . ")";
}
if ($activePct >= ACTIVE_PCT_WARN) {
$problems[] = "Active workers at {$activePct}% of pool capacity";
}
if (!empty($problems)) {
$body = "FPM saturation alert on " . gethostname() . "\n\n";
$body .= implode("\n", $problems) . "\n\n";
$body .= "Current stats:\n" . $logLine . "\n";
alert($body);
}
function alert(string $message): void
{
mail(ALERT_EMAIL, '[FPM Alert] ' . gethostname(), $message);
// Also write to stderr so systemd/cron captures it.
fwrite(STDERR, $message . PHP_EOL);
}
Make it executable: chmod +x /usr/local/bin/fpm-monitor
Add the cron entry:
* * * * * root /usr/local/bin/fpm-monitor 2>>/var/log/fpm-monitor-errors.log
That's it. One minute resolution, persistent log, email on breach.
The Gotchas That Bit Me
The max children reached counter is cumulative, not current. It increments every time FPM hits the pool ceiling and never resets until FPM restarts. If you alert on "greater than zero" you'll get paged once and then never again, even if saturation is happening constantly. I track the delta between readings instead - store the last value in a temp file and alert when it increases.
listen queue len is the kernel backlog, not the FPM queue. listen queue is the number of connections currently waiting. listen queue len is the maximum the kernel will hold before refusing connections. These are different things and the naming is confusing. Watch listen queue (the current depth) not listen queue len (the ceiling).
Dynamic vs static vs ondemand pools behave differently. With pm = dynamic, FPM spawns workers up to pm.max_children. With pm = static, all workers are always running. With pm = ondemand, workers spawn per request and die after idle. The idle processes count means something different in each mode. I nearly misread an ondemand pool as critically undersized because idle was always near zero - that's normal for ondemand.
The status page blocks too. The status request consumes a worker just like any other request. On a fully saturated pool, your status poller will queue along with everyone else. I've had the monitor report "endpoint unreachable" during the exact incidents I needed it most. The fix is to run a second small pool (a "status" pool with two static workers) dedicated to serving the status page and any health checks. It's a few extra lines in your pool config and completely worth it.
Slow request logging is separate. The slow requests counter only increments if you have request_slowlog_timeout set in your pool config. Without it the counter stays zero regardless of how slow your requests actually are. Enable it - it's off by default and nobody told me that for an embarrassingly long time.
When I Reach for This
Every production server I manage gets this monitor. Full stop. It takes fifteen minutes to set up and I've used it to catch real problems on a healthcare client's server (a cron job that queued 400 database jobs simultaneously), on an e-commerce site during a sale spike, and on a biotech's internal app that was slowly leaking FPM workers due to a misconfigured opcache invalidation loop.
I don't reach for a full APM product like Datadog or New Relic for small-to-medium managed hosting. The cost-to-value ratio doesn't work for clients running three to five Laravel apps on a VPS. This cron approach gives me 80% of the saturation signal for essentially no recurring cost.
If you're on a larger infrastructure with Prometheus already deployed, skip this and use php-fpm_exporter to scrape the same endpoint into Grafana. That's the right tool at scale. But for the five-server managed hosting shop I run out of Seattle, cron plus a log file is plenty.
What I would not do is rely solely on Nginx or PHP error logs to detect saturation. By the time 502s show up in your logs, users have already felt it. The FPM status page shows you the pressure building - queues growing, idle count dropping - before the threshold gets crossed. That lead time is the whole point.
The Log File Is Your History
One underrated benefit: fpm-monitor.log becomes a time-series record of your pool behavior. After a slow week I'll run a quick grep to find peak active-process readings and correlate them to deploys or traffic spikes:
grep 'active_pct=9' /var/log/fpm-monitor.log | head -20
That one-liner has helped me justify pool size increases to clients more than once. Hard numbers beat gut feelings every time.
Closing
PHP-FPM has told you everything you need to know about pool health for years - you just had to enable one config line and ask. If you're running PHP in production without at least occasionally checking these numbers, you're flying blind. Set this up today, it takes less time than reading this post.
Need help shipping something like this? Get in touch.