andrewdyer/shutdown-handler 问题修复 & 功能扩展

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

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

andrewdyer/shutdown-handler

Composer 安装命令:

composer require andrewdyer/shutdown-handler

包简介

A shutdown handler for Slim Framework applications that converts fatal errors into consistent HTTP responses

README 文档

README

A shutdown handler for Slim Framework applications that converts fatal errors into consistent HTTP responses.

Latest Stable Version Total Downloads License PHP Version Require

Introduction

This library provides a shutdown handler for Slim Framework applications, intercepting fatal errors that would otherwise result in unhandled crashes and transforming them into consistent HTTP responses. The handler is fully composable, allowing different responder and emitter strategies to be combined as required, and integrates seamlessly with existing Slim error handling and response emission workflows to maintain predictable application behaviour.

Prerequisites

  • PHP: Version 8.3 or higher is required.
  • Composer: Dependency management tool for PHP.
  • Slim Framework: Version 4 is required.

Installation

composer require andrewdyer/shutdown-handler

Getting Started

An error responder and response emitter are required before registering the shutdown handler.

1. Create an error responder

Error responders define how errors are transformed into HTTP responses.

use AndrewDyer\ShutdownHandler\Contracts\ErrorResponderInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Throwable;

final class MyErrorResponder implements ErrorResponderInterface
{
    public function createResponse(
        ServerRequestInterface $request,
        Throwable $exception,
        bool $displayErrorDetails
    ): ResponseInterface {
        // Custom response logic
    }
}

Alternatively, wrap existing logic using CallableErrorResponder:

use AndrewDyer\ShutdownHandler\Adapters\CallableErrorResponder;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Throwable;

$errorResponder = new CallableErrorResponder(
    static fn (
        ServerRequestInterface $request,
        Throwable $exception,
        bool $displayErrorDetails
    ): ResponseInterface => $httpErrorHandler(
        $request,
        $exception,
        $displayErrorDetails,
        false,
        false
    )
);

The callable must accept a request, exception, and display flag, and return a PSR-7 response.

2. Create a response emitter

Response emitters are responsible for sending responses to the client.

use AndrewDyer\ShutdownHandler\Contracts\ResponseEmitterInterface;
use Psr\Http\Message\ResponseInterface;

final class MyResponseEmitter implements ResponseEmitterInterface
{
    public function emit(ResponseInterface $response): void
    {
        // Custom emit logic
    }
}

Alternatively, wrap an existing emitter using CallableResponseEmitter:

use AndrewDyer\ShutdownHandler\Adapters\CallableResponseEmitter;
use Psr\Http\Message\ResponseInterface;

$responseEmitter = new CallableResponseEmitter(
    static fn (ResponseInterface $response): void => $slimEmitter->emit($response)
);

The adapter wraps an existing emitter implementation.

Usage

Register the shutdown handler to convert fatal errors into consistent HTTP responses:

use AndrewDyer\ShutdownHandler\ShutdownHandler;

$shutdownHandler = new ShutdownHandler(
    $request,
    $errorResponder,
    $responseEmitter,
    $displayErrorDetails
);

register_shutdown_function($shutdownHandler);

The $errorResponder and $responseEmitter values can come from custom implementations or the callable adapters shown in Getting Started.

License

Licensed under the MIT license and is free for private or commercial projects.

andrewdyer/shutdown-handler 适用场景与选型建议

andrewdyer/shutdown-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 81 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「slim」 「shutdown」 「error-handling」 「psr-7」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 andrewdyer/shutdown-handler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 andrewdyer/shutdown-handler 我们能提供哪些服务?
定制开发 / 二次开发

基于 andrewdyer/shutdown-handler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-07