fullpipe/check-them 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 fullpipe/check-them 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8.92k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 32
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 32
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-08