定制 68publishers/health-check 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

68publishers/health-check

最新稳定版本:v1.1.1

Composer 安装命令:

composer require 68publishers/health-check

包简介

Check the status of an application services.

README 文档

README

???? Health check for external services that are important for your application.

Checks Coverage Status Total Downloads Latest Version PHP Version

Installation

The best way to install 68publishers/health-check is using Composer:

$ composer require 68publishers/health-check

Standalone usage

use SixtyEightPublishers\HealthCheck\ExportMode; use SixtyEightPublishers\HealthCheck\HealthChecker; use SixtyEightPublishers\HealthCheck\ServiceChecker\PDOServiceChecker; use SixtyEightPublishers\HealthCheck\ServiceChecker\RedisServiceChecker; $checker = new HealthChecker(); $checker->addServiceChecker(new PDOServiceChecker('pgsql:host=127.0.0.1;port=5432;dbname=example', 'user', 'password')); $checker->addServiceChecker(new RedisServiceChecker()) # check all services $result = $checker->check(); # you can throw an exception if (!$result->isOk()) { throw $result->getError(); } # or covert the result into a JSON echo json_encode($result); # check Redis only $result = $checker->check(['redis']); # check in the "Full" mode. The default mode is "Simple". $result = $checker->check(NULL, ExportMode::Full); # the result now contains detailed information about each service echo json_encode($result);

Available service checkers

  • PDO - SixtyEightPublishers\HealthCheck\ServiceChecker\PDOServiceChecker
  • Doctrine DBAL - SixtyEightPublishers\HealthCheck\ServiceChecker\DbalConnectionServiceChecker
  • Redis - SixtyEightPublishers\HealthCheck\ServiceChecker\RedisServiceChecker
  • Http - SixtyEightPublishers\HealthCheck\ServiceChecker\HttpServiceChecker

You can create your own service checker. Just create a class that implements the interface ServiceCheckerInterface.

Integration into Nette Framework

The package provides compiler extensions for easy integration with Nette Framework.

Configuration example

extensions: 68publishers.health_check: SixtyEightPublishers\HealthCheck\Bridge\Nette\DI\HealthCheckExtension 68publishers.health_check: service_checkers: - SixtyEightPublishers\HealthCheck\ServiceChecker\RedisServiceChecker() - SixtyEightPublishers\HealthCheck\ServiceChecker\PDOServiceChecker::fromParams([ driver: pgsql host: '127.0.0.1' port: 5432 dbname: example user: user password: password ]) - MyCustomServiceChecker('foo') export_mode: full_if_debug # This is the default value. Supported values are "full_if_debug", "full", "simple" or custom service that implements an interface "ExportModeResolverInterface".

Now the service of type SixtyEightPublishers\HealthCheck\HealthCheckerInterface is accessible in DIC.

Health check using Symfony Console

extensions: 68publishers.health_check: SixtyEightPublishers\HealthCheck\Bridge\Nette\DI\HealthCheckExtension 68publishers.health_check.console: SixtyEightPublishers\HealthCheck\Bridge\Nette\DI\HealthCheckConsoleExtension

Now you can run this command:

$ bin/console health-check [<services>] [--export-mode <mode>]

Health check using Nette Application

extensions: 68publishers.health_check: SixtyEightPublishers\HealthCheck\Bridge\Nette\DI\HealthCheckExtension 68publishers.health_check.application: SixtyEightPublishers\HealthCheck\Bridge\Nette\DI\HealthCheckApplicationExtension 68publishers.health_check.application: route: '/health-check' # The default value. You can change it or set it as "false".

The extension automatically appends the health check route into your RouteList. If you want to disable this behaviour, please set the option route to false and add the route to your route factory manually e.g.:

<?php namespace App; use Nette\Application\Routers\RouteList; use SixtyEightPublishers\HealthCheck\Bridge\Nette\Application\HealthCheckRoute; class RouteFactory { public static function create(): RouteList { $router = new RouteList(); $router->add(new HealthCheckRoute('/health-check')); # ... other routes ... return $router; } }

Now you can check your services through an endpoint your-domain.com/health-check. The endpoint returns the status code 200 if everything is ok and 503 if some service check failed.

Contributing

Before opening a pull request, please check your changes using the following commands

$ make init # to pull and start all docker images $ make cs.check $ make stan $ make tests.all

统计信息

  • 总下载量: 4.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04