fliglio / health
Fliglio Health
Installs: 29 702
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 8
Forks: 0
Open Issues: 0
Requires
- php: ^7.4||^8
- psr/log: 1.*
Requires (Dev)
- fliglio/http: 2.1.*
- mockery/mockery: 1.*
- php-amqplib/php-amqplib: 3.*
- phpunit/phpunit: ^8
Suggests
- ext-pdo: For mysql health checks
- fliglio/http: For Fliglio apps only. HTTP reporting.
- php-amqplib/php-amqplib: For RabbitMQ health checks
This package is auto-updated.
Last update: 2024-12-15 00:22:08 UTC
README
fliglio-healthcheck
Extensible suite of health checks for PHP services, complete with custom behaviors to suit your health check consumer's needs. Default health checks include Mysql, Rabbit, Memcache, Can Write File, SSH and HttpResolver.
Install With Composer
{
"require" : {
"fliglio/health" : "2.1.*"
}
}
Example One, Basic MySql Check:
$manager = new HealthManager(); $manager->addCheck(new MysqlCheck('localhost', 'myuser', 'password')); echo json_encode($manager->process());
If your connection information is good, you should see:
{"status":"UP", "mysql::localhost;myuser":"UP"}
If the connection is not good, for whatever reason, you'll get:
{"status":"DOWN", "mysql::localhost;myuser":"DOWN"}
Example Two, Optional Checks:
$manager = new HealthManager(); $manager->addCheck(new MysqlCheck('localhost', 'myuser', 'password')) ->addOptionalCheck(new RabbitCheck('localhost', '/', 'myuser', 'password')); echo json_encode($manager->process());
If the optional check is down, the status will remain "UP". Example:
{"status":"UP", "mysql::localhost;myuser":"UP", "rabbit::localhost;myuser":"WARN"}
Behavior Example:
Depending on your apps health check reporting needs, you can add behaviors.
$response = new fliglio\Response(); $manager = new HealthManager(); $manager->addBehavior(new LogFailuresBehavior()) ->addBehavior(new LogWarningsBehavior()) ->addBehavior(new SilentOutputBehavior()) ->addBehavior(new StatusCodeBehavior($response); $manager->addCheck(new MysqlCheck('localhost', 'myuser', 'password')); echo json_encode($manager->process());
If the check is up, you will get HTTP 200 and a single json property. Example:
{"status":"UP"}
If the check is down, you will get HTTP 500, a message in the php log and a single json property. Example:
{"status":"DOWN"}
Silent Output + Logging Caveat:
If you want to log issue + have silent output, you have to put the SilentOutputBehavior after the loggers - otherwise the loggers wont know if there were any issues.
$manager = new HealthManager(); $manager->addBehavior(new LogIssuesBehavior()) ->addBehavior(new SilentOutputBehavior());
Public AWS ALB Behavior Example:
$response = new fliglio\Response(); $manager = new HealthManager(); $manager->addBehavior(new SilentOutputBehavior()) ->addBehavior(new StatusCodeBehavior($response);
Custom Health Checks:
You can add your own custom health checks, just implement the interface Fliglio\Health\Api\HealthCheck. If you want that health check to log, you'll need to implement the HealthCheckReport interface in addition to adding the LogFailuresBehavior/LogWarningsBehavior behavior.