alcamo/http

Extension of some laminas classes, in particular to stream process output

Installs: 126

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/alcamo/http

0.11.0 2026-01-14 17:04 UTC

This package is auto-updated.

Last update: 2026-01-14 17:04:28 UTC


README

FileResponse

use alcamo\http\FileResponse;

$response = FileResponse::newFromPath('/srv/www/htdocs/foo.xml');

$response->emit();

This sends an HTTP response with Content-Type and Content-Length headers. It may be more efficient than doing the same thing simply with Laminas\Diactoros\Response because is sends the file via fpassthru(), without need to keep the entire file content in memory.

PipeStream

use alcamo\http\{PipeStream, Response};
use alcamo\process\OutputProcess;

$stream = new PipeStream(new OutputProcess('/usr/bin/convert foo.png jpeg:-'));

$response = new Response(
    [ [ 'dc:format', 'image/jpeg' ] ],
    $stream
);

$response->emit();

This sends an HTTP response with Content-Type header. Again, it may be more efficient than doing the same thing simply with Laminas\Diactoros\Response because is sends the file via fpassthru(), without need to keep the entire data in memory.

The example also illustrates a possible use of the Response class, giving RDFa metadata which is automatically converted into HTTP headers.

Simple status page

use alcamo\http\Response;

$response = Response::newFromStatusAndText(403);

$response->emit();

This will send an HTTP response with Content-Type: text/plain and Content-Length header, with status code 403 and the text "Forbidden".