Looking to hire Laravel developers? Try LaraJobs

laravel-health maintained by itmosoft

Last update
2026/11/26 10:51 (dev-main)
License
Links
Downloads
0

Comments
comments powered by Disqus

ITMOSOFT Laravel Health

Extensible health checks for Laravel 12 and 13 applications.

Requirements

  • PHP 8.3+
  • Laravel 12 or 13

Installation

composer require itmosoft/laravel-health
php artisan vendor:publish --tag=health-config

The package is auto-discovered by Laravel.

Run checks

php artisan health:check
php artisan health:check --json

The command exits with a non-zero status when a critical check fails.

Built-in checks

  • Application bootstrap and environment metadata
  • PHP runtime version and memory limit
  • Database connection and SELECT 1
  • Cache write/read/delete probe
  • Configured filesystem write/read/delete probe
  • Pending application migrations

Cache and storage probes use unique temporary keys/files and best-effort cleanup. Configure the storage disk with HEALTH_STORAGE_DISK or health.storage.disk.

Register custom checks

Implement ItmoSoft\Health\Contracts\HealthCheck:

use ItmoSoft\Health\Contracts\HealthCheck;
use ItmoSoft\Health\DTOs\HealthCheckResult;

class StoreConfigurationCheck implements HealthCheck
{
    public function name(): string
    {
        return 'store-configuration';
    }

    public function run(): HealthCheckResult
    {
        return config('app.name')
            ? HealthCheckResult::healthy($this->name(), 'Store configuration is available.')
            : HealthCheckResult::warning($this->name(), 'Application name is not configured.');
    }
}

Register it in an application service provider:

use ItmoSoft\Health\Facades\Health;

Health::register(StoreConfigurationCheck::class);

Or add the class to health.checks in config/health.php.

JSON endpoints

Endpoints are disabled by default. To enable:

// config/health.php
'endpoint' => [
    'enabled' => true,
    'path' => 'health',
    'middleware' => ['api'],
    'liveness_path' => 'health/live',
    'readiness_path' => 'health/ready',
],
  • GET /health: complete health summary
  • GET /health/live: process liveness only
  • GET /health/ready: readiness based on configured checks

Protect detailed endpoints with suitable middleware or network-level access controls before enabling them publicly. Liveness does not run dependency checks. The status endpoint returns HTTP 503 for critical status; warning/unknown currently return HTTP 200.

Result statuses

healthy, warning, critical, unknown.

Health results intentionally avoid returning exception messages or secrets. Exceptions are reported to the application's configured logger.

Configuration

Publish the config with php artisan vendor:publish --tag=health-config.

  • health.checks: check classes to run
  • health.database.probe: enable database query probe
  • health.database.check_migrations: inspect pending application migrations
  • health.cache.probe: enable cache probe
  • health.storage.disk: storage disk to probe; defaults to filesystem default
  • health.storage.probe: enable storage probe
  • health.endpoint: optional HTTP endpoints

Testing

composer install
composer test

Security notes

  • Do not expose detailed health endpoints publicly without access controls.
  • Health check messages should not contain credentials, tokens, SQL, or exception traces.
  • Storage probes write a short-lived random file and attempt cleanup.
  • This package does not implement a web dashboard or persistent history in v1.0.0.

License

MIT.