Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Http Response Emitter

Emits a Response to the PHP Server API.

The available emitter implementations are.

- `Narrowspark\HttpEmitter\SapiEmitter`
- `Narrowspark\HttpEmitter\SapiStreamEmitter`.

Note: each use the native PHP functions header() and echo to emit the response.

Note: if headers have been sent, or the output buffer exists, and has a non-zero length, the emitters raise an exception, as mixed PSR-7 / output buffer content creates a blocking issue.

If you are emitting content via echo, print, var_dump, etc., or not catching PHP errors / exceptions, you will need to either fix your app to always work with a PSR-7 response. Or provide your own emitters that allow mixed output mechanisms.


composer require narrowspark/http-emitter


How to use the SapiEmitter:


use Narrowspark\HttpEmitter\SapiEmitter;

$response = new \Response();
$response->getBody()->write("some content\n");

$emitter = new SapiEmitter();

If you missing the Content-Length header you can use the \Narrowspark\HttpEmitter\Util\Util::injectContentLength static method.


use Narrowspark\HttpEmitter\Util;

$response = new \Response();

$response = Util::injectContentLength($response);


This library follows semantic versioning, and additions to the code ruleset are performed in major releases.


Please have a look at


If you would like to help take a look at the list of issues and check our Contributing guild.

Code of Conduct

Please have a look at


This package is licensed using the MIT License.

Please have a look at