wyrihaximus / react-psr-7-stream
🎁 Decorate ReactPHP streams as PSR-7 streams
Fund package maintenance!
WyriHaximus
Requires
- php: ^8.1
- psr/http-message: ^1.0
- react/async: ^4.0
- react/promise-stream: ^1.5
- react/stream: ^1.2
Requires (Dev)
- react/event-loop: ^1.3
- react/http: ^1.8
- wyrihaximus/async-test-utilities: ^5.0.23
This package is auto-updated.
Last update: 2024-12-03 19:55:18 UTC
README
🎁 Decorate ReactPHP streams as PSR-7 streams
Installation
To install via Composer, use the command below, it will automatically detect the latest version and bind it with ^
.
composer require wyrihaximus/react-psr-7-stream
Usage
This package assumes you run all code using it inside fibers. The following example makes a HTTP request using
react/http
, decorates the body, and loops over it until the full
body has been received. Important, while looping, do not use any other await
calls whatsoever inside the loop. Doing so might make you miss a data
event from the ReadableStreamInterface
. This
package is build for high performance low memory usage, it will not buffer data for you.
$response = await((new Browser())->requestStreaming('GET', 'https://example.com')); assert($response instanceof ResponseInterface); $body = $response->getBody(); assert($body instanceof ReadableStreamInterface); $stream = new Stream($body); while (! $stream->eof()) { handleDataChunk($stream->read(PHP_INT_MAX)); }
License
The MIT License (MIT)
Copyright (c) 2023 Cees-Jan Kiewiet
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.