PHPackages                             lgarret/health-check-bundle - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. lgarret/health-check-bundle

ActiveSymfony-bundle[Logging &amp; Monitoring](/categories/logging)

lgarret/health-check-bundle
===========================

Symfony bundle providing a /health endpoint to monitor application and dependency status

v1.0.3(2mo ago)0109↓50%MITPHPPHP &gt;=8.2CI passing

Since Mar 4Pushed 2mo agoCompare

[ Source](https://github.com/LouisGarret/health-check-bundle)[ Packagist](https://packagist.org/packages/lgarret/health-check-bundle)[ RSS](/packages/lgarret-health-check-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (16)Versions (5)Used By (0)

HealthCheckBundle
=================

[](#healthcheckbundle)

[![CI](https://github.com/LouisGarret/health-check-bundle/actions/workflows/ci.yml/badge.svg)](https://github.com/LouisGarret/health-check-bundle/actions/workflows/ci.yml)[![Latest Stable Version](https://camo.githubusercontent.com/91b7b7533b95d4f5eda330e77193469ccb7f553abbbf826908ee5634e3e17db7/68747470733a2f2f706f7365722e707567782e6f72672f6c6761727265742f6865616c74682d636865636b2d62756e646c652f76)](https://packagist.org/packages/lgarret/health-check-bundle)[![License](https://camo.githubusercontent.com/c2bc7abee84e19c4aa6a9bbd35d6a87edc727659bf083864cec02a10d207dd7a/68747470733a2f2f706f7365722e707567782e6f72672f6c6761727265742f6865616c74682d636865636b2d62756e646c652f6c6963656e7365)](https://packagist.org/packages/lgarret/health-check-bundle)

A Symfony bundle providing a `/health` endpoint to monitor your application and its dependencies.

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

[](#installation)

```
composer require lgarret/health-check-bundle
```

### Register the bundle

[](#register-the-bundle)

```
// config/bundles.php
return [
    // ...
    Lgarret\HealthCheckBundle\HealthCheckBundle::class => ['all' => true],
];
```

### Import routes

[](#import-routes)

```
# config/routes/health_check.yaml
health_check:
    resource: '@HealthCheckBundle/config/routes.php'
```

### Allow public access

[](#allow-public-access)

If you use the Symfony SecurityBundle, make sure the health route is publicly accessible:

```
# config/packages/security.yaml
security:
    access_control:
        - { path: ^/health$, roles: PUBLIC_ACCESS }
        # ...
```

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

[](#configuration)

```
# config/packages/health_check.yaml
health_check:
    path: '/health'                           # Route path (default: /health)
    secret: '%env(HEALTH_CHECK_SECRET)%'      # Optional — token to access detailed results
    header: 'X-Health-Token'                  # Optional — custom header name (default: Authorization)
    timeout: 5                                # Optional — max seconds per check (default: 5)
    cache:
        enabled: true                         # Optional — cache check results (default: true)
        ttl: 300                              # Optional — cache duration in seconds (default: 300)
    checks:
        doctrine: true                        # Optional — auto-register Doctrine DBAL checks (default: true)
        asset_mapper: true                    # Optional — auto-register AssetMapper check (default: true)
```

OptionTypeDefaultDescription`path``string``/health`URL path for the health check endpoint.`secret``string?``null`Token expected in the configured header. If `null`, details are never exposed.`header``string``Authorization`Name of the HTTP header used to send the secret token.`timeout``int``5`Maximum execution time in seconds for each individual check.`cache.enabled``bool``true`Enable caching of health check results.`cache.ttl``int``300`Cache TTL in seconds (5 minutes by default).`checks.doctrine``bool``true`Auto-register Doctrine DBAL checks (one per connection) if `doctrine/dbal` is installed.`checks.asset_mapper``bool``true`Auto-register AssetMapper check if `symfony/asset-mapper` is installed.Usage
-----

[](#usage)

### `GET /health`

[](#get-health)

**Without auth header** (or without a configured secret):

```
GET /health
→ 200 {"status": "ok"}
→ 503 {"status": "ko"}

```

**With a valid auth header**:

```
GET /health
X-Health-Token: my-secret-token

→ 200 {"status": "ok", "checks": {"database": {"status": "ok"}, "redis": {"status": "ok"}}}
→ 503 {"status": "ko", "checks": {"database": {"status": "ok"}, "redis": {"status": "ko", "error": "Connection refused"}}}

```

### Console command

[](#console-command)

Run checks from the command line:

```
bin/console health:check
```

```
Health Check
============

 ---------- -------- --------------------
  Check      Status   Error
 ---------- -------- --------------------
  database   ✓ OK
  redis      ✗ KO     Connection refused
 ---------- -------- --------------------

 [ERROR] 1 of 2 check(s) failed.

```

### Built-in checks

[](#built-in-checks)

The bundle ships with built-in checks that are **automatically registered** when the corresponding packages are installed:

CheckPackage requiredWhat it does`doctrine``doctrine/dbal`Runs `SELECT 1` on each configured DBAL connection`asset_mapper``symfony/asset-mapper`Checks that `manifest.json` exists (assets compiled)Built-in checks are enabled by default and auto-detected via `class_exists()` and service availability. One check is registered per Doctrine connection (e.g. `doctrine_default`, `doctrine_analytics`). The asset mapper check verifies that `public/assets/manifest.json` exists (i.e. `asset-map:compile` has been run). You can disable them in your configuration:

```
health_check:
    checks:
        doctrine: false
        asset_mapper: false
```

### Creating a custom check

[](#creating-a-custom-check)

Implement `HealthCheckInterface` — the service will be automatically discovered and registered:

```
