# Health Check Configuration Template — 503.my.id

Copy, adjust the limits to your stack, and test the alert once.
Values in brackets come from the 503.my.id lab (PHP-FPM pool of 5 workers,
16 November 2026). Scale the percentages, not the raw numbers.

## 1. Endpoints to check

| Check | Target | Interval | Timeout | Healthy |
|---|---|---|---|---|
| Static control | `/` (a plain file, no PHP) | 60s | 5s | HTTP 200 |
| Dynamic health | `/health.php` (see section 3) | 60s | 10s | HTTP 200 + `"status": "ok"` |
| Origin direct | Same health URL, bypassing the CDN | 5 min | 10s | HTTP 200 |

The static check is only a control. It proves the web server is alive.
It must never be your only check: in our lab it stayed green through a
full PHP-FPM outage.

## 2. Metrics and alert thresholds

| Signal | Warning (wake a human later) | Alert (wake a human now) |
|---|---|---|
| Pool workers busy | >= 80% for 2 checks [lab: 4 of 5] | Pool full + health probe failing |
| Health endpoint | Answers `"degraded"` | HTTP 503 or no answer, 2 checks in a row |
| Listen queue | > 0 for 2 checks | Growing for 5 minutes |
| Origin response time | p95 above your slowest real page | Timeouts on the health probe |
| `max_children reached` counter | Increased since yesterday | Increased in the last hour |

Alert on two consecutive failures, not one: single blips are network noise.
Warning on saturation, not downtime: a full pool is visible minutes before
visitors see the first 503, if you watch the worker count.

## 3. The health endpoint (PHP-FPM + nginx)

Run the endpoint in its own tiny pool, or it starves with the app it watches.

nginx — expose it to your monitor and localhost only:

```nginx
location = /health.php {
    allow 127.0.0.1;
    allow [MONITOR_IP];
    deny all;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/run/php/health.sock;
    fastcgi_read_timeout 15s;
}
```

PHP-FPM — a separate pool named `health` (static, 2 workers) beside your
app pool, plus `pm.status_path = /app-status` on the app pool.

`health.php` — probe the app, read its counters, answer JSON:

- App probe fails or times out -> HTTP 503, `"status": "error"`
- App answers, workers busy >= 80% -> HTTP 200, `"status": "degraded"`
- App answers, workers below 80% -> HTTP 200, `"status": "ok"`

Healthy response (measured in our lab):

```json
{
    "status": "ok",
    "time": "2026-11-16T15:36:58+00:00",
    "checks": {
        "app_probe": "pass",
        "app_workers_active": 1,
        "app_workers_idle": 1,
        "app_workers_max": 5,
        "app_listen_queue": 0,
        "max_children_reached_total": 0
    },
    "duration_ms": 131
}
```

## 4. Test the alert once

1. Point both checks at a staging copy.
2. Shrink the app pool (`pm.max_children = 5`) and hold its workers with
   slow requests.
3. Confirm: static check still green, dynamic check red, alert delivered
   and timestamped.
4. Restore the pool. If the alert never arrived, the monitor is decoration.

---
503.my.id — The 503 Error Diagnostic Center
Full guide: /website-health-checks/
