PHPackages                             ans-group/laravel-health-check - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ans-group/laravel-health-check

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ans-group/laravel-health-check
==============================

A package for checking the health of your Laravel/Lumen applications.

v2.1.1(1y ago)167930.0k—9.2%47[1 PRs](https://github.com/ans-group/laravel-health-check/pulls)2MITPHPPHP ^8.1CI failing

Since Feb 14Pushed 6mo ago9 watchersCompare

[ Source](https://github.com/ans-group/laravel-health-check)[ Packagist](https://packagist.org/packages/ans-group/laravel-health-check)[ RSS](/packages/ans-group-laravel-health-check/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (19)Versions (40)Used By (2)

[![UKFast Logo](https://camo.githubusercontent.com/51188f1ebbb9dddb6c0605e7090af67643c3a54f862bd284d6d93e90b2dea20b/68747470733a2f2f696d616765732e756b666173742e636f2e756b2f6c6f676f732f756b666173742f343431783132365f7472616e73706172656e745f73747261706c696e652e706e67)](https://camo.githubusercontent.com/51188f1ebbb9dddb6c0605e7090af67643c3a54f862bd284d6d93e90b2dea20b/68747470733a2f2f696d616765732e756b666173742e636f2e756b2f6c6f676f732f756b666173742f343431783132365f7472616e73706172656e745f73747261706c696e652e706e67)

[![Tests](https://github.com/ukfast/laravel-health-check/workflows/Run%20tests/badge.svg?branch=master)](https://github.com/ukfast/laravel-health-check/workflows/Run%20tests/badge.svg?branch=master)

Health Check Package
====================

[](#health-check-package)

The purpose of this package is to surface a health-check endpoint on `/health` which, when hit, returns the status of all the services and dependencies your project relies on, along with the overall health of your system. This is useful in both development and production for debugging issues with a faulty application.

This package also adds a `/ping` endpoint. Just hit `/ping` and receive `pong` in response.

Installation
------------

[](#installation)

To install the package:

Run `composer require ans-group/laravel-health-check` to add the package to your dependencies.

This will automatically install the package to your vendor folder.

#### Laravel

[](#laravel)

In Laravel applications, the service provider should be automatically registered, but you may register it manually in your `config/app.php` file:

```
'providers' => [
    // ...
    UKFast\HealthCheck\HealthCheckServiceProvider::class,
];
```

#### Lumen

[](#lumen)

To have the package function in Lumen, you need to register the service provider. add the following to your `bootstrap/app.php` file:

```
$app->register(\UKFast\HealthCheck\HealthCheckServiceProvider::class);
```

You can test that the package is working correctly by hitting the `/health` endpoint.

Configuration
-------------

[](#configuration)

### Laravel

[](#laravel-1)

##### Facade

[](#facade)

We surface a `HealthCheck` facade with the package. You can use the `passes`, `fails`, or `all` methods, if you want to access the results of a check or the number of checks running from within your code.

```
if (HealthCheck::passes('env')) {
    // check passed
}

if (HealthCheck::fails('http')) {
    // check failed
}

$numberOfChecks = HealthCheck::all()->count();
```

If one of the checks provided cannot be resolved from the service container, we'll throw a `CheckNotFoundException` with the name of the missing check.

##### Config

[](#config)

If you'd like to tweak the config file (helpful for configuring the `EnvHealthCheck`, for example), you can publish it with:

```
php artisan vendor:publish --provider="UKFast\HealthCheck\HealthCheckServiceProvider" --tag="config"
```

##### Console command

[](#console-command)

Check all: `php artisan health-check:status`

Only specific checks: `php artisan health-check:status --only=log,cache`

Except specific checks: `php artisan health-check:status --except=cache`

##### Middleware

[](#middleware)

You can register custom middleware to run on requests to the `/health` endpoint. You can add this to the middleware array in the `config/healthcheck.php` config file created by the command above, as shown in the example below:

```
/**
 * A list of middleware to run on the health-check route
 * It's recommended that you have a middleware that only
 * allows admin consumers to see the endpoint.
 *
 * See UKFast\HealthCheck\Middleware\BasicAuth for a one-size-fits all
 * solution
 */
'middleware' => [
    App\Http\Middleware\CustomMiddleware::class
],
```

Now your `CustomMiddleware` middleware will be ran on every request to the `/health` endpoint.

### Lumen

[](#lumen-1)

##### Facade

[](#facade-1)

We surface a `HealthCheck` facade with the package. You can use the `passes`, `fails`, or `all` methods, if you want to access the results of a check or the number of checks running from within your code.

```
if (HealthCheck::passes('env')) {
    // check passed
}

if (HealthCheck::fails('http')) {
    // check failed
}

$numberOfChecks = HealthCheck::all()->count();
```

If one of the checks provided cannot be resolved from the service container, we'll throw a `CheckNotFoundException` with the name of the missing check.

##### Config

[](#config-1)

If you'd like to tweak the config file (helpful for configuring the `EnvHealthCheck`, for example):

Manually copy the package config file (see example below) to `config\healthcheck.php` (you may need to create the config directory if it does not already exist).

```
