Search by

brightfish / health-checks

pecuchetbrightfish

Simple health checks for Laravel

Package info

github.com/brightfish-be/health-checks

pkg:composer/brightfish/health-checks

Statistics

Installs: 433

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.10.0 2026-08-24 07:50 UTC

This package is auto-updated.

Last update: 2026-08-24 07:50:20 UTC


README

Tests Latest Version on Packagist Total Downloads

Compatibility

Package PHP Laravel Lumen
0.10.x 8.3, 8.4 12.x, 13.x
0.9.x 8.2+ 12.x
0.8.x 8.0+ 9.x, 10.x yes

Lumen support was dropped in 0.10: there is no Lumen release for Laravel 12 or 13. Applications still on Laravel 10 or Lumen should stay on ^0.8.

Usage

Run all your registered checks from the command line:

php artisan health:check

Or make an HTTP request to the built-in health endpoint:

curl https://your.app/health

The endpoint returns 200 when every check passes. The first failing check aborts the run and returns its own message and HTTP status code as text/plain.

Installation

Install the package with composer:

composer require brightfish/health-checks

The service provider is registered automatically through package auto-discovery.

Publish the config file:

php artisan vendor:publish --tag="health-checks-config"

Create a custom health check class:

namespace App\Health;

class MyCustomCheck extends \Brightfish\HealthChecks\Checks\AbstractCheck
{
    public function run(): bool
    {
        return false;
    }

    public function getMessage(): string
    {
        return 'Error';
    }
}

Finally, list up the class in the config file:

return [
    'checks' => [
        \App\Health\MyCustomCheck::class,
    ],
];

Configuration

config/health.php holds three sections. The package ships defaults, so it works before you publish anything.

Key Default Description
checks [] Check classes, run in order. Each must extend AbstractCheck.
router.path /health Endpoint URI. Set to a falsy value to register no route at all.
router.middleware [] Middleware applied to the endpoint.
router.log_time false Record a timestamp every time a route is matched.
artisan.cmd_namespace App\Console\Commands Only commands in this namespace get their finish time recorded.
artisan.log_time true Record a timestamp whenever such a command finishes.

The route is registered under the name health.check.

Checking how long ago something ran

When artisan.log_time is on, the finish time of each of your own commands is cached. A check can read those timestamps through the protected helpers on AbstractCheck:

class ImportAgeCheck extends \Brightfish\HealthChecks\Checks\AbstractCheck
{
    public function run(): bool
    {
        $secondsDiff = $this->diffFromNow('app:import');

        if (is_null($secondsDiff) || $secondsDiff > 3600) {
            $this->setMessage('The import did not run in the last ' . $this->diffForHumans(3600));

            return false;
        }

        return true;
    }
}

getTime($key) returns the raw timestamp, diffFromNow($key) the age in seconds (or null if the key was never recorded), and diffForHumans($seconds) a readable duration.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

GNU General Public License (GPL). Please see License File for more information.