redwebcreation/laravel-healthful
Composer 安装命令:
composer require redwebcreation/laravel-healthful
包简介
Checks if your application is healthy.
README 文档
README
This package is meant to be used with Docker's HEALTHCHECK directive and has been designed accordingly.
Installation
Requires PHP 8.0+
You can install the package via composer:
composer require redwebcreation/laravel-healthful
The package will automatically register itself.
You'll need to publish the migrations :
php artisan vendor:publish --tag="healthful-migrations"
Optionally you can publish the config file:
php artisan vendor:publish --tag="healthful-config"
This is the contents of the published config file:
<?php use RWC\Healthful\Checks\DatabaseCheck; use RWC\Healthful\Checks\QueueCheck; use RWC\Healthful\Checks\SchedulerCheck; return [ /* The route that should return the health status */ 'route' => '/_/health', /* A list of checks to be performed. */ 'checks' => [ DatabaseCheck::class, ] ];
Usage
Check if your application is healthy :
use RWC\Healthful\Facades\Health; Health::check();
It returns true if all the checks were true or false if one failed.
You may want to expose your application's health publicly :
use RWC\Healthful\Facades\Health; Health::route()->name('healthcheck');
It registers a route at /_/health that returns a 200 if all the checks passed, or a 503 if one of them doesn't.
Custom checks
// app/HealthChecks/IsMondayCheck.php use RWC\Healthful\Checks\Check; class IsMondayCheck implements Check { public function passes() : bool{ // Monday is never healthful. return !now()->isMonday(); } }
// config/healthful.php return [ 'checks' => [ // ... IsMondayCheck::class ] ];
You can also use the Heartbeat model :
use RWC\Healthful\Models\Heartbeat; $heartbeat = Heartbeat::firstOrNew([ 'type' => 100 // any number above 100 ]); $heartbeat->updateTimestamps(); $heartbeat->save();
You need to specify a type above 100 so heartbeats of other kinds provided by this package won't ever collide with
yours.
Then, in your check : <
use RWC\Healthful\Checks\Check; use RWC\Healthful\Models\Heartbeat; class MyCheck implements Check { public function passes(): bool { $heartbeat = Heartbeat::query() ->where('type', 100) ->where('updated_at', '>=', now()->subMinutes(5)) ->first(); return $heartbeat !== null; } }
Integration with Docker
# Dockerfile HEALTHCHECK --interval=1m --timeout=30s --retries=3 CMD curl --fail http://localhost/_/health || exit 1
Testing
composer test
Healthful for Laravel was created by Félix Dorn under the MIT license.
redwebcreation/laravel-healthful 适用场景与选型建议
redwebcreation/laravel-healthful 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 409 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 06 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 redwebcreation/laravel-healthful 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 redwebcreation/laravel-healthful 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 409
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-06-05