PHPackages                             andrewdyer/shutdown-handler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. andrewdyer/shutdown-handler

ActiveLibrary[HTTP &amp; Networking](/categories/http)

andrewdyer/shutdown-handler
===========================

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

0.1.4(1mo ago)087MITPHPPHP ^8.3CI passing

Since Apr 7Pushed 1mo agoCompare

[ Source](https://github.com/andrewdyer/shutdown-handler)[ Packagist](https://packagist.org/packages/andrewdyer/shutdown-handler)[ Docs](https://github.com/andrewdyer/shutdown-handler)[ RSS](/packages/andrewdyer-shutdown-handler/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (5)Dependencies (15)Versions (5)Used By (0)

Shutdown Handler
================

[](#shutdown-handler)

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

[![Latest Stable Version](https://camo.githubusercontent.com/bcfafe3891aac9bf157fb406f70829e8c4152e171b9d6ca6c43aafcc8adb2df0/687474703a2f2f706f7365722e707567782e6f72672f616e64726577647965722f73687574646f776e2d68616e646c65722f763f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andrewdyer/shutdown-handler)[![Total Downloads](https://camo.githubusercontent.com/40c2281935540c394b58b3d5440ddaf2101edd70f79970d95ac6aa758b919c40/687474703a2f2f706f7365722e707567782e6f72672f616e64726577647965722f73687574646f776e2d68616e646c65722f646f776e6c6f6164733f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andrewdyer/shutdown-handler)[![License](https://camo.githubusercontent.com/5051ed466b865957331ec3fa2dbe7c76bc47a8a7dfa166d7729e40489aaed4f7/687474703a2f2f706f7365722e707567782e6f72672f616e64726577647965722f73687574646f776e2d68616e646c65722f6c6963656e73653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andrewdyer/shutdown-handler)[![PHP Version Require](https://camo.githubusercontent.com/f1842b58402fb698cf82582caf0de27ffa224025a42d88cb282a5d0306210f18/687474703a2f2f706f7365722e707567782e6f72672f616e64726577647965722f73687574646f776e2d68616e646c65722f726571756972652f7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andrewdyer/shutdown-handler)

Introduction
------------

[](#introduction)

This library provides a shutdown handler for [Slim Framework](https://www.slimframework.com/) 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
-------------

[](#prerequisites)

- **[PHP](https://www.php.net/)**: Version 8.3 or higher is required.
- **[Composer](https://getcomposer.org/)**: Dependency management tool for PHP.
- **[Slim Framework](https://www.slimframework.com/)**: Version 4 is required.

Installation
------------

[](#installation)

```
composer require andrewdyer/shutdown-handler
```

Getting Started
---------------

[](#getting-started)

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

### 1. Create an error responder

[](#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

[](#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
-----

[](#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
-------

[](#license)

Licensed under the [MIT license](https://opensource.org/licenses/MIT) and is free for private or commercial projects.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance89

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~23 days

Total

4

Last Release

54d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/666597ea6e46748a89fe8764d1a45b4d0da97daf1bb1e9770ea34ae41f706d08?d=identicon)[andrewdyer](/maintainers/andrewdyer)

---

Top Contributors

[![andrewdyer](https://avatars.githubusercontent.com/u/8114523?v=4)](https://github.com/andrewdyer "andrewdyer (16 commits)")

---

Tags

error-handlingphppsr-7shutdownslimpsr-7phpslimerror handlingshutdown

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/andrewdyer-shutdown-handler/health.svg)

```
[![Health](https://phpackages.com/badges/andrewdyer-shutdown-handler/health.svg)](https://phpackages.com/packages/andrewdyer-shutdown-handler)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B4.3k](/packages/guzzlehttp-psr7)[oat-sa/tao-core

TAO core extension

65147.9k149](/packages/oat-sa-tao-core)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

36826.2k2](/packages/telnyx-telnyx-php)[maurobonfietti/rest-api-slim-php

Example of REST API with Slim PHP Framework.

3041.7k](/packages/maurobonfietti-rest-api-slim-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
