Maintenance

Create Health Checks for PHP Applications

Expose useful liveness and readiness checks without leaking infrastructure details or making monitoring itself a source of load.

Overview

Health checks help an orchestrator or monitoring service decide whether an application process is alive and whether it can serve traffic. A single endpoint that runs every expensive dependency test can create more problems than it solves.

Separate liveness and readiness

A liveness check should answer whether the application process is functioning. It should be fast and avoid failing merely because a downstream service is temporarily unavailable. A readiness check can verify critical dependencies required to serve requests, such as database connectivity.

Keep checks bounded

Use short connection and query timeouts. Do not scan tables, run reports or call every external integration on each health request. Cache dependency results briefly if checks are frequent, and ensure the cache does not hide a prolonged outage.

Return simple status

Use a small response such as 200 OK when ready and an appropriate non-2xx response when not ready. Do not expose database hostnames, credentials, stack traces or internal network details. Detailed diagnostics belong in protected monitoring and logs.

Avoid cascading failures

If every instance performs expensive dependency checks every second, an already struggling database may receive even more load. Use reasonable intervals, jitter and timeouts. Health checks should be cheaper than normal application requests.

Operational checklist

  • Define liveness and readiness separately.
  • Keep each check fast and bounded.
  • Use short timeouts for dependencies.
  • Do not disclose internal configuration.
  • Avoid expensive queries and repeated external calls.
  • Alert on trends, not only a single failed probe.

References

Kubernetes Liveness, Readiness and Startup Probes · PHP PDO

Share this page Help other developers discover this resource.