renoki-co/laravel-healthchecks
Composer 安装命令:
composer require renoki-co/laravel-healthchecks
包简介
Laravel Healthchecks is a simple controller class that helps you build your own healthchecks endpoint without issues.
README 文档
README
Laravel Healthchecks is a simple controller class that helps you build your own healthchecks endpoint without issues.
🤝 Supporting
If you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, sponsor our work with Github Sponsors. 📦
🚀 Installation
You can install the package via composer:
composer require renoki-co/laravel-healthchecks
🙌 Usage
First of all, you should create your own Controller for healthchecks, that extends the RenokiCo\LaravelHealthchecks\Http\Controllers\HealthcheckController.
use Illuminate\Http\Request; use RenokiCo\LaravelHealthchecks\Http\Controllers\HealthcheckController; class MyHealthcheckController extends HealthcheckController { /** * Register the healthchecks. * * @param \Illuminate\Http\Request $request * @return void */ public function registerHealthchecks(Request $request) { $this->addHealthcheck('mysql', function (Request $request) { // Try testing the MySQL connection here // and return true/false for pass/fail. return true; }); } }
// In your routes Route::get('/healthcheck', [MyHealthcheckController::class, 'handle']);
Registering healthchecks
Within the controller, you should register the healthchecks closures in the registerHealthchecks method, like the example stated above.
You can add as many healthchecks as you want.
public function registerHealthchecks(Request $request) { $this->addHealthcheck('mysql', function (Request $request) { // }); $this->addHealthcheck('redis', function (Request $request) { // }); $this->addHealthcheck('some_check', function (Request $request) { // }); $this->addHealthcheck('another_check_here', function (Request $request) { // }); }
Status Codes
In case of failure, the response is 500. For all successful responses, the status code is 200.
To change the http codes being sent out, specify this in your registerHealthchecks method:
public function registerHealthchecks(Request $request) { $this->setPassingHttpCode(203); $this->setFailingHttpCode(403); $this->addHealthcheck('mysql', function (Request $request) { return true; }); }
Outputs
By default, the output will be OK or FAIL as string, but in case you want to debug the healthchecks, you can get a JSON with each registered healthchecks and their pass/fail closures.
You have just to call withOutput():
public function registerHealthchecks(Request $request) { $this->withOutput(); $this->addHealthcheck('mysql', function (Request $request) { return true; }); $this->addHealthcheck('redis', function (Request $request) { return false; }); }
The output in the browser would be like this:
{
"mysql": true,
"redis": false
}
🐛 Testing
vendor/bin/phpunit
🤝 Contributing
Please see CONTRIBUTING for details.
🔒 Security
If you discover any security related issues, please email alex@renoki.org instead of using the issue tracker.
🎉 Credits
renoki-co/laravel-healthchecks 适用场景与选型建议
renoki-co/laravel-healthchecks 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 54.98k 次下载、GitHub Stars 达 56, 最近一次更新时间为 2020 年 05 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「controller」 「server」 「laravel」 「endpoint」 「checks」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 renoki-co/laravel-healthchecks 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 renoki-co/laravel-healthchecks 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 renoki-co/laravel-healthchecks 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Give your JS App some Backbone with Models, Views, Collections, and Events.
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
A jQuery augmented PHP library for creating and validating HTML forms
annotations-scan-plugin
Create mail from controller action render
Extended auth components for Yii2
统计信息
- 总下载量: 54.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 56
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2020-05-15