fullpipe/check-them
Composer 安装命令:
composer require fullpipe/check-them
包简介
Health checks for external services
关键字:
README 文档
README
Install
composer require fullpipe/check-them
Usage
use Fullpipe\CheckThem\Checks\PDOCheck; $mysqlCheck = new PDOCheck('mysql:dbname=test_db;host=127.0.0.1:3306', 'username', 'password'); $status = $mysqlCheck->getStatus(); if(!$status->isUp()) { $this->logger->warn('Mysql server is down', $status->getError()); exit; }
or use AllInOneCheck
use Fullpipe\CheckThem\Checks\AllInOneCheck; use Fullpipe\CheckThem\Checks\PDOCheck; use Fullpipe\CheckThem\Checks\HttpCheck; use Fullpipe\CheckThem\Checks\RedisChecker; ... $allInOne = new AllInOneCheck(); $allInOne->add(new PDOCheck('mysql:dbname=test_db;host=127.0.0.1:3306', 'username', 'password')); $allInOne->add(new HttpCheck('user_service:8080')); $allInOne->add(new RedisChecker('redis:6379')); $status = $allInOne->getStatus(); if(!$status->isUp()) { $this->logger->warn('Something is down', $status->getError()); exit; } // everything is fine
Available checks
PDOCheck
It is just a simple wrapper over php.PDO.
It has the same constructor signature as the PDO class. In theory, it works with all
PDO drivers, but was tested
only against MySQL and Postgres.
Examples
use Fullpipe\CheckThem\Checks\PDOCheck; ... $mysqlCheck = new PDOCheck('mysql:dbname=test_db;host=127.0.0.1:3306', 'username', 'password'); $pgCheck = new PDOCheck('pgsql:host=localhost;port=8002;dbname=test_db', 'username', 'password');
HttpCheck
Check external service by http request. To be up service should respond with
200 http code.
Examples
use Fullpipe\CheckThem\Checks\HttpCheck; ... $userCheck = new HttpCheck('http://user_service:8080/healthz'); $webCheck = new HttpCheck('https://google.com/');
Config
$check = (new HttpCheck('http://user_service:8080/healthz')) ->setConnectionTimeout(3) // change connection timeout, default 1 second ;
RedisCheck
Checks redis server with PING -> PONG request.
Examples
use Fullpipe\CheckThem\Checks\RedisCheck; ... $check = new RedisCheck('tcp://10.0.0.1:6379'); $check = new RedisCheck('unix:/path/to/redis.sock');
Config
$check = (new RedisCheck('redis:6379')) ->setAuth('test_pass') // use password if required ->setConnectionTimeout(4) // timeout for server connection, default 1 second ->setStreamTimeout(3) // timeout for socket read/write operations, default 1 second ;
PredisCheck
If you already work with redis using predis.
You could use predis client for PING check.
Examples
use Fullpipe\CheckThem\Checks\PredisCheck; ... $client = new Predis\Client([ 'scheme' => 'tcp', 'host' => '10.0.0.1', 'port' => 6379, ]); $check = new PredisCheck($client);
SocketCheck
Connects to service and waits for single char from service over a socket connection.
Examples
use Fullpipe\CheckThem\Checks\SocketCheck; ... // you could use this check for mysql, // it work fine and you don't need a password $check = new SocketCheck('mysql:3306');
Config
$check = (new SocketCheck('mysql:3306')) ->setConnectionTimeout(4) // timeout for server connection, default 1 second ->setStreamTimeout(3) // timeout for socket read/write operations, default 1 second ;
SocketConnectionCheck
Checks only that socket connection is working. It is not the check that you could rely on.
Examples
use Fullpipe\CheckThem\Checks\SocketConnectionCheck; ... $check = new SocketConnectionCheck('rabbitmq:5672');
Config
$check = (new SocketConnectionCheck('mysql:3306')) ->setConnectionTimeout(4) // timeout for server connection, default 1 second ;
AllInOneCheck
Checks all children to be available.
Examples
use Fullpipe\CheckThem\Checks\AllInOneCheck; use Fullpipe\CheckThem\Checks\SocketCheck; use Fullpipe\CheckThem\Checks\RedisCheck; ... $check = (new AllInOneCheck()) ->add(new SocketCheck('mysql:3306')) ->add((new RedisCheck('tcp://10.0.0.1:6379'))->setAuth('redisPass')) ;
Test
composer install docker-compose -f tests/docker-compose.yml up -d ./vendor/bin/phpunit
or if you want to play with service availability
docker-compose -f tests/docker-compose.yml up -d php ./tests/realtime_test.php docker-compose -f tests/docker-compose.yml restart mysql57
fullpipe/check-them 适用场景与选型建议
fullpipe/check-them 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.92k 次下载、GitHub Stars 达 32, 最近一次更新时间为 2020 年 11 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「health check」 「k8s」 「healthz」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fullpipe/check-them 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fullpipe/check-them 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fullpipe/check-them 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony bundle for chameleon-system/sanitycheck
This Extension integrates a credit check and more made by the LEONEX Risk Management Platform into your order process. Extensive configuration and evaluation options is provided in the Platform
Is your Laravel app OK? Health checks running in production to ensure you can sleep well at night and be sure everything is still OK.
Provides healthcheck endpoints in accordance with IETF's healthcheck draft RFC
Provide status and health api endpoints
Generates Kubernetes API objects from the OpenAPI spec.
统计信息
- 总下载量: 8.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 32
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-08