Emitting psr-7 responses.
Two implementations currently available:
Each use the native PHP functions
echo in order to emit the response.
If you are using a non-SAPI implementation, you will need to create your own
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
var_dump, etc., or not catching PHP errors / exceptions, you will need to either fix your application to always work with a PSR-7 response. Or provide your own emitters that allow mixed output mechanisms.
composer require narrowspark/http-emitter
<?php use Narrowspark\HttpEmitter\SapiEmitter; $response = new \Response(); $response->getBody()->write("some content\n"); $emitter = new SapiEmitter(); $emitter->emit($response);
If you missing the
Content-Length header you need to use
<?php $response = new \Response(); $response = Util::injectContentLength($response);
Note: Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
The Narrowspark http-emitter is open-sourced software licensed under the MIT license