yiisoft/psr-emitter

PSR-7 HTTP response emitter

1.0.0 2025-05-21 06:26 UTC

This package is auto-updated.

Last update: 2025-05-21 13:08:09 UTC


README

Yii

Yii PSR Emitter


Latest Stable Version Total Downloads Build status Code Coverage Mutation testing badge Static analysis type-coverage psalm-level

The package provides EmitterInterface that is responsible for sending PSR-7 HTTP responses as well as several implementations of the interface:

  • SapiEmitter - sends a response using standard PHP Server API;
  • FakeEmiiter - a fake emitter that does nothing, except for capturing response (useful for testing purposes).

Additionally, the package provides EmitterMiddleware PSR-15 middleware that can be used in an application to send a response by any EmitterInterface implementation.

Requirements

  • PHP 8.1 or higher.

Installation

The package could be installed with Composer:

composer require yiisoft/psr-emitter

General usage

Create emitter instance and call emit() method with a PSR-7 response:

use Psr\Http\Message\ResponseInterface;
use Yiisoft\PsrEmitter\SapiEmitter;

/** @var Response $response */

$emitter = new SapiEmitter();
$emitter->emit($response);

You can customize the buffer size (by default, 8MB) for large response bodies:

use Psr\Http\Message\ResponseInterface;
use Yiisoft\PsrEmitter\SapiEmitter;

/** @var Response $response */

$emitter = new SapiEmitter(4_194_304); // Buffer size is 4MB

// Response content will be sent in chunks of 4MB
$emitter->emit($response);

Documentation

If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.

License

The Yii PSR Emitter is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack