PHPackages                             menumbing/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. menumbing/health-check

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

menumbing/health-check
======================

Cloud native health check component for Hyperf

0884PHP

Since Apr 4Pushed 3mo agoCompare

[ Source](https://github.com/menumbing/health-check)[ Packagist](https://packagist.org/packages/menumbing/health-check)[ RSS](/packages/menumbing-health-check/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Menumbing Health Check
======================

[](#menumbing-health-check)

Cloud native health check component for [Hyperf](https://hyperf.io). Provides Kubernetes-compatible liveness and readiness probe endpoints with built-in checkers for common services.

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

[](#installation)

```
composer require menumbing/health-check
```

Publish the configuration file:

```
php bin/hyperf.php vendor:publish menumbing/health-check
```

This will create `config/autoload/health_check.php`.

Endpoints
---------

[](#endpoints)

Once installed, two HTTP endpoints are automatically registered:

EndpointPurpose`/health/liveness`Returns whether the application is running. A failure triggers a restart.`/health/readiness`Returns whether the application is ready to accept traffic.Both endpoints return JSON with HTTP `200` when healthy or `503` when unhealthy.

**Liveness response example:**

```
{
  "status": "alive",
  "services": {
    "memory_consumption": {
      "name": "memory",
      "status": true,
      "message": "Memory usage is OK"
    }
  }
}
```

**Readiness response example:**

```
{
  "status": "ready",
  "services": {
    "database": {
      "name": "db",
      "status": true,
      "message": "Database connection is OK"
    },
    "redis": {
      "name": "redis",
      "status": true,
      "message": "Redis connection is OK"
    },
    "amqp": {
      "name": "amqp",
      "status": true,
      "message": "AMQP connection is OK"
    }
  }
}
```

Built-in Checkers
-----------------

[](#built-in-checkers)

CheckerNameRequired PackageDescription`DbChecker``db``hyperf/db-connection`Verifies database connectivity via `SELECT 1`.`MemoryChecker``memory`-Checks if memory usage is within the allowed limit.`RedisChecker``redis``hyperf/redis`Pings the Redis server to verify connectivity.`AmqpChecker``amqp``hyperf/amqp`Verifies the AMQP (RabbitMQ) connection status.Configuration
-------------

[](#configuration)

The configuration file (`config/autoload/health_check.php`) has three sections:

### Checks

[](#checks)

Define which checks to run for each probe type:

```
'checks' => [
    'liveness' => [
        'memory_consumption' => [
            'checker' => 'memory',
            'options' => ['max_memory' => 1000], // Max memory in MB
        ],
    ],
    'readiness' => [
        'database' => [
            'checker' => 'db',
            'options' => ['connection' => 'default'],
        ],
        'redis' => [
            'checker' => 'redis',
            'options' => ['pool' => 'default'],
        ],
        'amqp' => [
            'checker' => 'amqp',
            'options' => ['pool' => 'default'],
        ],
    ],
],
```

### Routes

[](#routes)

Configure the HTTP server and endpoint paths:

```
'route' => [
    'server' => 'http',
    'paths' => [
        'liveness'  => '/health/liveness',
        'readiness' => '/health/readiness',
    ],
],
```

Set a path to `null` to disable that endpoint.

### Checkers

[](#checkers)

Register all available checker classes:

```
'checkers' => [
    Menumbing\HealthCheck\Checker\DbChecker::class,
    Menumbing\HealthCheck\Checker\MemoryChecker::class,
    Menumbing\HealthCheck\Checker\RedisChecker::class,
    Menumbing\HealthCheck\Checker\AmqpChecker::class,
],
```

Only include checkers for packages that are installed in your project. Remove any checker whose corresponding package is not available.

Checker Options
---------------

[](#checker-options)

### DbChecker

[](#dbchecker)

OptionTypeDefaultDescription`connection`string`'default'`Database connection name.### MemoryChecker

[](#memorychecker)

OptionTypeDefaultDescription`max_memory`int/null`null`Maximum memory usage in MB. `null` to skip the check.### RedisChecker

[](#redischecker)

OptionTypeDefaultDescription`pool`string`'default'`Redis pool name.### AmqpChecker

[](#amqpchecker)

OptionTypeDefaultDescription`pool`string`'default'`AMQP pool name.Custom Checker
--------------

[](#custom-checker)

Create a custom checker by implementing `Menumbing\Contract\HealthCheck\CheckerInterface`:

```
