PHPackages                             68publishers/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. [CLI &amp; Console](/categories/cli)
4. /
5. 68publishers/health-check

ActiveLibrary[CLI &amp; Console](/categories/cli)

68publishers/health-check
=========================

Check the status of an application services.

v1.1.1(10mo ago)35.2k↓47.5%[2 issues](https://github.com/68publishers/health-check/issues)1MITPHPPHP ^8.1CI passing

Since Aug 5Pushed 10mo ago1 watchersCompare

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

READMEChangelog (8)Dependencies (14)Versions (10)Used By (1)

Health check
============

[](#health-check)

💗 Health check for external services that are important for your application.

[![Checks](https://camo.githubusercontent.com/cdd7d9b76b8f7cfd9255a6872c47d13c0f85816ce3eac2187fa8a55829b6eb8f/68747470733a2f2f62616467656e2e6e65742f6769746875622f636865636b732f36387075626c6973686572732f6865616c74682d636865636b2f6d6173746572)](https://github.com/68publishers/health-check/actions)[![Coverage Status](https://camo.githubusercontent.com/39fac5c86a7a5820fc9cf5b0d9825650fb54667384fc7320995481eb8e08a7ca/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f36387075626c6973686572732f6865616c74682d636865636b2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/68publishers/health-check?branch=master)[![Total Downloads](https://camo.githubusercontent.com/0aa6189556988a7206c510c07bf11c6a55d80500a4d07d8dd01509d42a8f2b6f/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f64742f36387075626c6973686572732f6865616c74682d636865636b)](https://packagist.org/packages/68publishers/health-check)[![Latest Version](https://camo.githubusercontent.com/066e5b7dc8279bdea82356a8c4dc887896b21694f4167b210ba9811b95db1f7d/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f36387075626c6973686572732f6865616c74682d636865636b)](https://packagist.org/packages/68publishers/health-check)[![PHP Version](https://camo.githubusercontent.com/cb8455a6020a3658733cd08d582361d1aadec19e5d4e89d3f413a40e97e5e0bc/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f7068702f36387075626c6973686572732f6865616c74682d636865636b)](https://packagist.org/packages/68publishers/health-check)

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

[](#installation)

The best way to install `68publishers/health-check` is using Composer:

```
$ composer require 68publishers/health-check
```

Standalone usage
----------------

[](#standalone-usage)

```
use SixtyEightPublishers\HealthCheck\ExportMode;
use SixtyEightPublishers\HealthCheck\HealthChecker;
use SixtyEightPublishers\HealthCheck\ServiceChecker\PDOServiceChecker;
use SixtyEightPublishers\HealthCheck\ServiceChecker\RedisServiceChecker;

$checker = new HealthChecker();
$checker->addServiceChecker(new PDOServiceChecker('pgsql:host=127.0.0.1;port=5432;dbname=example', 'user', 'password'));
$checker->addServiceChecker(new RedisServiceChecker())

# check all services
$result = $checker->check();

# you can throw an exception
if (!$result->isOk()) {
    throw $result->getError();
}

# or covert the result into a JSON
echo json_encode($result);

# check Redis only
$result = $checker->check(['redis']);

# check in the "Full" mode. The default mode is "Simple".
$result = $checker->check(NULL, ExportMode::Full);

# the result now contains detailed information about each service
echo json_encode($result);
```

Available service checkers
--------------------------

[](#available-service-checkers)

- PDO - `SixtyEightPublishers\HealthCheck\ServiceChecker\PDOServiceChecker`
- Doctrine DBAL - `SixtyEightPublishers\HealthCheck\ServiceChecker\DbalConnectionServiceChecker`
- Redis - `SixtyEightPublishers\HealthCheck\ServiceChecker\RedisServiceChecker`
- Http - `SixtyEightPublishers\HealthCheck\ServiceChecker\HttpServiceChecker`

You can create your own service checker. Just create a class that implements the interface `ServiceCheckerInterface`.

Integration into Nette Framework
--------------------------------

[](#integration-into-nette-framework)

The package provides compiler extensions for easy integration with Nette Framework.

### Configuration example

[](#configuration-example)

```
extensions:
    68publishers.health_check: SixtyEightPublishers\HealthCheck\Bridge\Nette\DI\HealthCheckExtension

68publishers.health_check:
    service_checkers:
        - SixtyEightPublishers\HealthCheck\ServiceChecker\RedisServiceChecker()
        - SixtyEightPublishers\HealthCheck\ServiceChecker\PDOServiceChecker::fromParams([
            driver: pgsql
            host: '127.0.0.1'
            port: 5432
            dbname: example
            user: user
            password: password
        ])
        - MyCustomServiceChecker('foo')
    export_mode: full_if_debug # This is the default value. Supported values are "full_if_debug", "full", "simple" or custom service that implements an interface "ExportModeResolverInterface".
```

Now the service of type `SixtyEightPublishers\HealthCheck\HealthCheckerInterface` is accessible in DIC.

### Health check using Symfony Console

[](#health-check-using-symfony-console)

```
extensions:
    68publishers.health_check: SixtyEightPublishers\HealthCheck\Bridge\Nette\DI\HealthCheckExtension
    68publishers.health_check.console: SixtyEightPublishers\HealthCheck\Bridge\Nette\DI\HealthCheckConsoleExtension
```

Now you can run this command:

```
$ bin/console health-check [] [--export-mode ]
```

### Health check using Nette Application

[](#health-check-using-nette-application)

```
extensions:
    68publishers.health_check: SixtyEightPublishers\HealthCheck\Bridge\Nette\DI\HealthCheckExtension
    68publishers.health_check.application: SixtyEightPublishers\HealthCheck\Bridge\Nette\DI\HealthCheckApplicationExtension

68publishers.health_check.application:
    route: '/health-check' # The default value. You can change it or set it as "false".
```

The extension automatically appends the health check route into your RouteList. If you want to disable this behaviour, please set the option `route` to `false` and add the route to your route factory manually e.g.:

```
