ipunkt / laravel-healthcheck
此包已被废弃,不再维护。未建议替代包。
laravel 的可配置健康检查路由
2.0.0
2020-11-06 11:21 UTC
Requires
- illuminate/database: ^5.0 || ^6.0 || ^7.0 || ^8.0
- illuminate/support: ^5.0 || ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- mockery/mockery: ^0.9
- phpunit/phpunit: ^5.0
- solarium/solarium: ^3.8
Suggests
- solarium/solarium: Necessary to check Apache Solr instance
README
laravel 的可配置健康检查路由
安装
composer require ipunkt/laravel-healthcheck
如果你使用的是 laravel 5.5 或更高版本,你不需要手动添加提供者。我们支持包发现。
将 \Ipunkt\LaravelHealthcheck\HealthcheckProvider::class,
添加到你的 config/app.php
文件中的 providers
部分。
php artisan vendor:publish --provider "Ipunkt\LaravelHealthcheck\HealthcheckProvider"
使用方法
编辑配置文件 config/healthcheck.php
有关更多信息,请参阅那里的注释
可用的检查器
database
通过 Eloquent 测试数据库连接storage
测试对文件系统路径的写入访问redis
测试访问 redis 队列服务solr
测试访问 solr 服务(需要额外的包 solarium/solarium)
扩展
要添加新的 Healthchecker,实现 Ipunkt\LaravelHealthcheck\HealthChecker\Checker
并将其注册到 Ipunkt\LaravelHealthcheck\HealthChecker\Factory\HealthcheckerFactory
。HealthcheckerFactory 作为单例注册,因此你可以在 ServiceProvider 的 boot
部分使用 App::make()
来检索它并注册你的检查器。
HealthcheckerFactory::register
- string $identifier - 当添加到
config('healthcheck.checks')
时将激活检查器的标识符 - Closure function(array $config) { return new Checker; } - 创建检查器的回调。接收
$config('healthcheck.$identifier')
作为参数。
示例
class ServiceProvider { public function boot() { /** * @var HealthcheckerFactory $factory */ $factory = $this->app->make('Ipunkt\LaravelHealthcheck\HealthChecker\Factory\HealthcheckerFactory'); $factory->register('identifier', function(array $config) { $newChecker = new ExampleChecker; $newChecker->setExampleOption( array_get($config, 'url', 'http://www.example.com') ); return $newChecker; }); } } class ExampleChecker implement Ipunkt\LaravelHealthcheck\HealthChecker\Checker { protected $url; public function setExampleOption($url) { $this->url = $url; } public function check() { $url = $this->url; if ( @file_get_contents($url) === false ) throw new CheckFailedException("Failed to retrieve $url."); } }