bear / streamer
BEAR.Sunday HTTP stream responder
Installs: 295 697
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 2
Open Issues: 1
Requires
- php: ^7.3 || ^8.0
- bear/resource: ^1.15.1
- bear/sunday: ^1.5
- ray/aop: ^2.10.4
- ray/di: ^2.11
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.4
- doctrine/annotations: ^1.7
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-04-11 02:09:23 UTC
README
A HTTP stream responder
Assign stream resource to resource-body.
class Image extends ResourceObject { use StreamTransferInject; public function onGet(string $name = 'inline image') : ResourceObject { $fp = fopen(__DIR__ . '/BEAR.jpg', 'r'); stream_filter_append($fp, 'convert.base64-encode'); // image base64 format $this->body = [ 'name' => $name, 'image' => $fp ]; return $this; } }
Or assign entire body.
class Download extends ResourceObject { use StreamTransferInject; public $headers = [ 'Content-Type' => 'image/jpeg', 'Content-Disposition' => 'attachment; filename="image.jpg"' ]; public function onGet() : ResourceObject { $fp = fopen(__DIR__ . '/BEAR.jpg', 'r'); $this->body = $fp; return $this; } }
Http body will not be output at once with "echo", Instead streamed with low memory consumption.