ovenlab/cakephp-health

Health checks and readiness/liveness probes for CakePHP 5 applications: pluggable checks (database, cache, disk, ...), JSON endpoints for Kubernetes/load balancers, and a CLI with meaningful exit codes.

Maintainers

Package info

github.com/OvenLab/cakephp-health

Homepage

Issues

Type:cakephp-plugin

pkg:composer/ovenlab/cakephp-health

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-08-19 15:47 UTC

This package is auto-updated.

Last update: 2026-08-19 15:56:12 UTC


README

CI Latest Stable Version License

Health checks and readiness/liveness probes for CakePHP 5 applications.

Ship your app with the endpoints load balancers, Kubernetes, and uptime monitors expect — plus a CLI probe with a meaningful exit code — driven by a small set of pluggable checks.

  • GET /health/liveliveness: the process is up. Always 200. Public.
  • GET /health/readyreadiness: runs the checks; 503 when any is critical, otherwise 200. Public, and only ever exposes status strings.
  • GET /healthdetailed report (messages, data, per-check timings), guarded by a token and/or an IP allow-list.
  • bin/cake health — same checks from the CLI, exit code 1 on critical.

Requirements

  • PHP 8.1+
  • CakePHP 5.0+

Installation

composer require ovenlab/cakephp-health

Load the plugin (or add it to Application::bootstrap()):

bin/cake plugin load Health
// src/Application.php
public function bootstrap(): void
{
    parent::bootstrap();
    $this->addPlugin('Health');
}

Configuration

Copy the example config and adjust it:

cp vendor/ovenlab/cakephp-health/config/health.example.php config/health.php
use Health\Check\CacheCheck;
use Health\Check\DatabaseCheck;
use Health\Check\DiskSpaceCheck;

return [
    'Health' => [
        'checks' => [
            'database' => ['className' => DatabaseCheck::class, 'connection' => 'default'],
            'cache' => ['className' => CacheCheck::class, 'config' => 'default'],
            'disk' => [
                'className' => DiskSpaceCheck::class,
                'path' => TMP,
                'warningThreshold' => 80,  // percent used
                'criticalThreshold' => 95,
            ],
        ],
        'guard' => [
            'token' => env('HEALTH_TOKEN'),
            'allowIp' => [],
        ],
    ],
];

The plugin auto-loads config/health.php during bootstrap.

The detailed endpoint guard

GET /health/live and GET /health/ready are always public and only ever return status strings. GET /health also returns check messages and data, so it is guarded. Access is granted when:

  1. no guard is configured (handy for local dev), or
  2. the client IP is in guard.allowIp, or
  3. the request carries a matching token via the X-Health-Token header or the ?token= query string.
curl -H "X-Health-Token: $HEALTH_TOKEN" https://example.com/health

Built-in checks

Check Class Key options
Database Health\Check\DatabaseCheck connection
Cache Health\Check\CacheCheck config
Disk space Health\Check\DiskSpaceCheck path, warningThreshold, criticalThreshold

Writing a custom check

Implement Health\Check\HealthCheckInterface and return a Result:

namespace App\Health;

use Health\Check\HealthCheckInterface;
use Health\Check\Result;

class QueueDepthCheck implements HealthCheckInterface
{
    public function __construct(private array $options = [])
    {
    }

    public function name(): string
    {
        return 'queue';
    }

    public function run(): Result
    {
        $depth = /* ... */ 0;
        $max = $this->options['max'] ?? 1000;

        if ($depth >= $max) {
            return Result::critical("Queue backlog is {$depth}", ['depth' => $depth]);
        }

        return Result::ok("Queue backlog is {$depth}", ['depth' => $depth]);
    }
}

Then register it in config/health.php:

'queue' => ['className' => \App\Health\QueueDepthCheck::class, 'max' => 500],

A check should never throw — report failures as Result::critical(). If one does throw, the runner catches it and reports the check as critical, so a single broken check can never take down the whole probe.

Kubernetes example

livenessProbe:
  httpGet: { path: /health/live, port: 80 }
readinessProbe:
  httpGet: { path: /health/ready, port: 80 }

CLI

bin/cake health          # exit 0 on ok/warning, 1 on critical
bin/cake health --strict # exit 1 on warning too

License

MIT © Vinicius Arantes