Hosting & Deployment

Server Health Checks and Service Readiness

Separate liveness and readiness checks and connect service health to monitoring, deployment gates, and incident response.

A health check should answer a specific operational question. A process can be running while the application is unable to serve requests because its database is unavailable, storage is full, or required configuration is missing. Distinguish liveness—whether a process should be restarted—from readiness—whether it can safely receive traffic.

Design separate checks

A liveness check should be cheap and avoid depending on every external service. If it fails, the process may be stuck or dead. A readiness check can verify essential dependencies such as database connectivity, required cache availability, and application initialization. Avoid making a readiness endpoint perform expensive queries or expose internal details.

An application endpoint might return a minimal status document:

{"status":"ok","service":"web"}

For a readiness response, include only safe, non-sensitive dependency state. Do not disclose database hostnames, credentials, internal paths, or stack traces.

Test the full request path

Check local service state and external reachability:

systemctl is-active nginx
systemctl is-active php-fpm
curl -fsS https://example.com/health

Service names and PHP-FPM unit names vary. A local HTTP check may bypass the CDN, load balancer, or TLS termination layer, so use both internal and external probes where appropriate.

Avoid restart loops

A dependency outage should not necessarily restart every web process. Use sensible timeouts, retry intervals, and failure thresholds. If a health check fails because a database is temporarily unavailable, restarting PHP-FPM repeatedly may increase load without fixing the dependency.

Operational use

Connect checks to monitoring and deployment gates. Before sending traffic to a new release, verify readiness. During an incident, compare health status with application error rates and dependency metrics. Keep health endpoints rate-limited or network-restricted if they reveal more than a simple status. Document which failures should trigger an alert, traffic removal, or process restart.

Share this page Help other developers discover this resource.