gouh/psr-health

It is a handler to be able to know if there are certain connections such as cache, database and some external endpoints

1.0.0 2021-05-18 21:58 UTC

This package is auto-updated.

Last update: 2024-04-20 05:28:52 UTC


README

It is a handler to be able to know if there are certain connections such as cache, database and some external endpoints

Built With

Config

If you use config aggregator add next line in the array

PsrHealth\ConfigProvider::class

If you use only psr container add next line in your factories

\PsrHealth\Health::class => \PsrHealth\HealthFactory::class

Config for psr-health, add an array like this in the project config

    'health' => [
        'mongo' => [
            'host' => 'local-mongo-44',
            'port' => 27017,
            'database' => 'local',
            'collection' => 'startup_log',
            'user' => 'admin',
            'password' => 'admin'
        ],
        'mysql' => [
            'host' => 'local-mysql-57',
            'port' => 3306,
            'database' => 'credit',
            'user' => 'hangouh',
            'password' => 'secret2'
        ],
        'redis' => [
            'host' => 'local-redis',
            'port' => 6379,
            'password' => 'password'
        ],
        'endpoint' => [
            'webhook' => [
                'url' => 'https://webhook.site/e8dc7d50-6985-4345-81d1-b45c30601403',
                'custom_headers' => [
                    'Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l'
                ]
            ],
            'hangouh' => 'https://hangouh.me'
        ]
    ]

You can confgure only what you require

    'health' => [
        'mysql' => [
            'host' => 'local-mysql-57',
            'port' => 3306,
            'database' => 'credit',
            'user' => 'hangouh',
            'password' => 'secret2'
        ],
        'redis' => [
            'host' => 'local-redis',
            'port' => 6379,
            'password' => 'password'
        ]
    ]

Usage

Get Health class from your container and inject in your class

$health = $container->get(Health::class);

The class has multiple connection tests you can use each one or together

$health->redisConnection();
$health->mysqlConnection();
$health->mongoConnection();
$health->endpointConnection();
# Or you can use
$health->getHealthStatus();