Lab-tested: PHP 8.4.27 health endpoint + curl monitor · 2 Dec 2026 · Reproduced and fixed in our lab
Fix Box — Try This First (10 Seconds)
You cannot prevent every 500. You can catch every 500 within a minute, before your visitors report it.
- Add a health endpoint that returns 200 only when the app truly works.
- Check it every minute from outside your own server.
- Alert on two failed checks in a row, not on one blip.
The Exact Symptoms
The worst 500 is the silent one. The site is down, and the first alert is a customer message hours later.
Without monitoring, discovery time is random. With monitoring, discovery time is your check interval.
What We Reproduced in the Lab
We built a health endpoint that returned 500 while a “broken” flag file existed. A simple curl loop checked it three times.
All three checks recorded status=500, one second apart. After we removed the flag, the same loop recorded status=200 three times.
check1 01:59:49 status=500
check2 01:59:49 status=500
check3 01:59:49 status=500
check1 01:59:49 status=200
check2 01:59:49 status=200
check3 01:59:49 status=200
The monitor caught the failure and the recovery with zero guesswork. That is the entire value of the setup.
The Setup
Make the health endpoint honest. It should touch the database and fail loudly if anything essential is broken.
<?php
// /health.php — 200 only when the app really works
$fp = @fsockopen("127.0.0.1", 3306, $e, $s, 2);
if (!$fp) { http_response_code(500); echo "db down"; exit; }
fclose($fp); echo "ok";
Then check it from outside the server, every 60 seconds. Alert after two consecutive failures to skip single network blips.
# Minimal external check (cron, every minute)
code=$(curl -s -o /dev/null -w "%{http_code}" https://example.com/health.php)
[ "$code" != "200" ] && echo "$(date -u) ALERT status=$code" >> /var/log/uptime.log
Decision Table
| Check result | Meaning | Action |
|---|---|---|
| 200, body “ok” | App and DB healthy | None |
| 500 from health endpoint | App or DB broken | Alert, read error log |
| Timeout | Server overloaded or down | Alert, check host |
| 200 but body wrong | Cache serving stale page | Bypass cache for /health.php |
What Did Not Work
Checking only the homepage failed us in an earlier test. A cached homepage returned 200 while the app behind it was dead.
Checking from the same server also missed real outages. If the host is down, the monitor is down with it.
Prevention
Pair monitoring with staging for updates. Monitoring tells you fast; staging stops the breakage from shipping at all.
Read the staging workflow in WordPress Staging and Safe Updates. For diagnosis once an alert fires, use PHP 500 Error.
Verify any URL on demand with the 500 Error Checker. The full diagnosis path lives in 500 Internal Server Error.
FAQ
How often should I check? Every 60 seconds is a sane default. Faster checks cost little and shrink discovery time.
Why alert on two failures, not one? Single failures are often network noise. Two in a row is a real signal.
Should the health page be public? It can be, if it reveals nothing sensitive. Keep the body to “ok” or a short reason.
Does monitoring prevent 500s? No. It converts silent downtime into a one-minute alert. Prevention comes from staging and testing.
What about error-rate alerts? Add them later. Start with uptime; it catches the failures that matter most.
Sources and date
Lab tests run 2 Dec 2026 on PHP 8.4.27 with a curl monitor loop. References checked live on the same date.
- RFC 9110 §15.6.1: https://www.rfc-editor.org/rfc/rfc9110.html
- MDN — 500: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/500
- PHP — fsockopen: https://www.php.net/manual/en/function.fsockopen.php
- WordPress — Common errors: https://wordpress.org/documentation/article/common-wordpress-errors/





Leave a Reply