gouh/psr-health

这是一个处理程序,可以了解是否存在某些连接,例如缓存、数据库和一些外部端点

1.0.0 2021-05-18 21:58 UTC

This package is auto-updated.

Last update: 2024-09-20 06:17:22 UTC


README

这是一个处理程序,可以了解是否存在某些连接,例如缓存、数据库和一些外部端点

使用技术

配置

如果你使用配置聚合器,请将下一行添加到数组中

PsrHealth\ConfigProvider::class

如果你仅使用psr容器,请将下一行添加到你的工厂中

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

psr-health的配置,请在项目配置中添加如下数组

    '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'
        ]
    ]

你可以仅配置所需的部分

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

用法

从你的容器中获取Health类并将其注入到你的类中

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

该类具有多个连接测试,你可以单独使用或一起使用

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