定制 renoki-co/laravel-healthchecks 二次开发

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

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

renoki-co/laravel-healthchecks

最新稳定版本:2.1.0

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

CI codecov StyleCI Latest Stable Version Total Downloads Monthly Downloads License

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

统计信息

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

GitHub 信息

  • Stars: 56
  • Watchers: 2
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2020-05-15