A extension for zend-diactoros.
SfpDiactoros\Response\SwitchingEmitter allows fpassthru() with FpassthruInterface.
just changed only in emitBody() from original Zend\Diactoros\Response\SapiEmitter.
// SapiEmitter
echo $response->getBody();// SwitchingEmitter
if ($body instanceof FpassthruInterface) {
$resource = $body->detach();
if ($body instanceof RewindFpassthruInterface) {
rewind($resource);
}
fpassthru($resource);
} else {
echo $response->getBody();
}use SfpDiactoros\Response\SwitchingEmitter;
$server = Server::createServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
$server->setEmitter(new SwitchingEmitter);use SfpDiactoros\Stream\RewindFpassthruStream;
$fp = fopen('/tmp/bigsize', 'r');
$response->withBody(new RewindFpassthruStream($fp));