Download the PHP package tiny-blocks/http-health-check without Composer
On this page you can find all versions of the php package tiny-blocks/http-health-check. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tiny-blocks/http-health-check
More information about tiny-blocks/http-health-check
Files in tiny-blocks/http-health-check
Package http-health-check
Short Description PSR-15 liveness and readiness request handlers with configurable health checks for HTTP services.
License MIT
Homepage https://github.com/tiny-blocks/http-health-check
Informations about the package http-health-check
Http Health Check
- Overview
- Installation
- How to use
- Liveness handler
- Readiness handler
- Database checks with Doctrine
- AWS SSM checks
- Drain marker
- Custom health checks
- Readiness payload
- License
- Contributing
Overview
Framework-agnostic, infrastructure-agnostic readiness and liveness checking, exposed over HTTP through PSR-15 request handlers.
The library separates two concerns. The domain (HealthCheck, Health, Status, Readiness,
HealthChecks, HealthReport) describes dependencies and aggregates their outcome without importing
Doctrine, AWS, or PSR. It is usable outside HTTP. The HTTP adapter (LivenessHandler,
ReadinessHandler, DrainMarker) is the deliverable you route your probes to.
Each dependency is registered as critical or optional. The aggregate readiness follows a single rule:
any critical check down makes the service UNAVAILABLE, otherwise any optional check down makes it
DEGRADED, otherwise it is HEALTHY. An empty set of checks is HEALTHY because nothing was
registered. The readiness endpoint maps that outcome to an HTTP status.
| Readiness | Meaning | HTTP status |
|---|---|---|
HEALTHY |
Every critical check is up and no optional check is down. | 200 |
DEGRADED |
Every critical check is up, at least one optional check down. | 200 |
UNAVAILABLE |
At least one critical check is down, or the service drains. | 503 |
Two concrete drivers ship with the library: DoctrineHealthCheck for databases and SsmHealthCheck
for AWS SSM. Their third-party packages are optional. Install doctrine/dbal only when you use the
Doctrine driver, and aws/aws-sdk-php only when you use the SSM driver. Every check exposes a generic
component() category (for example "database"), never a specific host or connection name.
Installation
How to use
Liveness handler
The liveness endpoint answers 200 as long as the process can serve the request. It runs no checks
and exists to tell an orchestrator whether the process should be restarted.
Readiness handler
The readiness endpoint runs every registered check and maps the aggregate readiness to an HTTP status.
Register each dependency as critical or optional. A critical failure returns 503, an optional
failure keeps 200 while reporting DEGRADED.
HealthChecks is immutable. Every withCritical and withOptional returns a new set, so the
original is never mutated.
Database checks with Doctrine
DoctrineHealthCheck verifies database availability by issuing a SQL query through a Doctrine DBAL
connection. The default probe is the platform's own dummy select, resolved from the connection, so it
works on any DBAL platform without assuming a specific database. Customize the probe query and the
report name when a service runs more than one database.
AWS SSM checks
SsmHealthCheck verifies AWS SSM availability through a lightweight describe call. Register it as
optional when the service can still serve traffic while SSM is unreachable.
Drain marker
A drain marker lets an orchestrator gracefully remove an instance from rotation. While the watched
file exists, the readiness endpoint short-circuits to 503 without running any check, so traffic
stops before the process shuts down. Use default() to watch /tmp/draining, or from() to watch a
custom path.
Custom health checks
Implement HealthCheck to verify any dependency. The component() is the generic category exposed in
the report, the optional name() distinguishes checks that share a component, and check() catches
its own infrastructure failures and reports a DOWN Health instead of letting the exception escape.
Readiness payload
A successful readiness response carries the aggregate status and one entry per check. The name and
detail fields appear only when present, so a check without a discriminator omits name, and a check
that is up omits detail.
When the service is draining, the readiness endpoint returns 503 with a minimal body and runs no
check.
License
Http Health Check is licensed under MIT.
Contributing
Please follow the contributing guidelines to contribute to the project.
All versions of http-health-check with dependencies
psr/http-message Version ^2.0
psr/http-server-handler Version ^1.0
tiny-blocks/collection Version ^2.6
tiny-blocks/http Version ^8.0
tiny-blocks/time Version ^2.7