tourze/psr15-health-check-request-handler 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

tourze/psr15-health-check-request-handler

最新稳定版本:0.0.1

Composer 安装命令:

composer require tourze/psr15-health-check-request-handler

包简介

PSR-15 Health Check Request Handler

README 文档

README

English | 中文

Latest Version PHP Version Require codecov License

A simple and lightweight PSR-15 Request Handler for health check endpoints, designed for easy integration into any HTTP service or middleware pipeline.

Features

  • Implements PSR-15 RequestHandlerInterface
  • Provides a basic health check endpoint, returning HTTP 200 with a customizable response
  • Supports custom health check paths
  • Customizable response body for healthy status
  • Returns HTTP 404 for non-health-check paths

Installation

Requirements:

  • PHP >= 8.1
  • psr/http-message, psr/http-server-handler, nyholm/psr7

Install via Composer:

composer require tourze/psr15-health-check-request-handler

Quick Start

Basic Usage

use Tourze\PSR15HealthCheckRequestHandler\HealthCheckRequestHandler;

$handler = new HealthCheckRequestHandler();
$response = $handler->handle($request); // $request must implement ServerRequestInterface

Default Behavior

By default, the handler responds with status 200 and body ok for the following paths:

  • /health
  • /health.php
  • /health.html
  • /health.asp

All other paths will receive a 404 Not Found response.

Customization

You can customize the health check paths and healthy response text (using reflection):

use ReflectionProperty;
use Tourze\PSR15HealthCheckRequestHandler\HealthCheckRequestHandler;

$handler = new HealthCheckRequestHandler();

// Change health check paths
$pathsProperty = new ReflectionProperty(HealthCheckRequestHandler::class, 'healthCheckPaths');
$pathsProperty->setAccessible(true);
$pathsProperty->setValue($handler, ['/custom-health']);

// Change healthy response text
$okTextProperty = new ReflectionProperty(HealthCheckRequestHandler::class, 'okText');
$okTextProperty->setAccessible(true);
$okTextProperty->setValue($handler, 'service is healthy');

Documentation

Contributing

  • Issues and pull requests are welcome.
  • Please follow PSR coding standards.
  • Run tests with PHPUnit before submitting PRs.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Changelog

See Releases for version history and upgrade notes.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-24