ReadableResourceStream
in package
implements
ReadableStream, ResourceStream, IteratorAggregate
uses
ReadableStreamIteratorAggregate, ForbidCloning, ForbidSerialization
Readable stream abstraction for PHP's stream resources.
Tags
Table of Contents
Interfaces
- ReadableStream
- A `ReadableStream` allows reading byte streams in chunks.
- ResourceStream
- IteratorAggregate
Constants
- DEFAULT_CHUNK_SIZE = 8192
Properties
- $callbackId : string
- $cancel : callable(CancelledException): void
- $chunkSize : int
- $continuousReads : int
- $defaultChunkSize : int
- $errorHandler : callable(): bool
- $onClose : DeferredFuture
- $readable : bool
- $resetContinuousReads : callable(): void
- $resource : resource|null
- $resumeSuspension : callable(): void
- $suspension : Suspension|null
- $useSingleRead : bool
Methods
- __construct() : mixed
- __destruct() : mixed
- __serialize() : never
- __unserialize() : never
- close() : void
- Closes the stream forcefully. Multiple `close()` calls are ignored.
- getIterator() : Traversable<int, string>
- getResource() : resource|object|null
- isClosed() : bool
- Returns whether this resource has been closed.
- isReadable() : bool
- onClose() : void
- Registers a callback that is invoked when this resource is closed.
- read() : string|null
- Reads data from the stream.
- reference() : void
- References the readable watcher, so the loop keeps running in case there's an active read.
- setChunkSize() : void
- unreference() : void
- Unreferences the readable watcher, so the loop doesn't keep running even if there are active reads.
- __clone() : mixed
- free() : void
- Nulls reference to resource, marks stream unreadable, and succeeds any pending read with null.
Constants
DEFAULT_CHUNK_SIZE
public
mixed
DEFAULT_CHUNK_SIZE
= 8192
Properties
$callbackId
private
string
$callbackId
$cancel read-only
private
callable(CancelledException): void
$cancel
$chunkSize
private
int
$chunkSize
$continuousReads
private
int
$continuousReads
= 0
$defaultChunkSize
private
int
$defaultChunkSize
$errorHandler
private
static callable(): bool
$errorHandler
$onClose read-only
private
DeferredFuture
$onClose
$readable
private
bool
$readable
= true
$resetContinuousReads read-only
private
callable(): void
$resetContinuousReads
$resource
private
resource|null
$resource
$resumeSuspension read-only
private
callable(): void
$resumeSuspension
$suspension
private
Suspension|null
$suspension
= null
$useSingleRead read-only
private
bool
$useSingleRead
Methods
__construct()
public
__construct(resource $stream[, positive-int $chunkSize = self::DEFAULT_CHUNK_SIZE ]) : mixed
Parameters
- $stream : resource
-
Stream resource.
- $chunkSize : positive-int = self::DEFAULT_CHUNK_SIZE
-
Default chunk size per read operation.
Tags
__destruct()
public
__destruct() : mixed
__serialize()
public
final __serialize() : never
Return values
never__unserialize()
public
final __unserialize(array<string|int, mixed> $data) : never
Parameters
- $data : array<string|int, mixed>
Return values
neverclose()
Closes the stream forcefully. Multiple `close()` calls are ignored.
public
close() : void
getIterator()
public
getIterator() : Traversable<int, string>
Return values
Traversable<int, string>getResource()
public
getResource() : resource|object|null
Return values
resource|object|null —The stream resource or null if the stream has closed.
isClosed()
Returns whether this resource has been closed.
public
isClosed() : bool
Return values
bool —true if closed, otherwise false.
isReadable()
public
isReadable() : bool
Return values
bool —A stream may become unreadable if the underlying source is closed or lost.
onClose()
Registers a callback that is invoked when this resource is closed.
public
onClose(Closure $onClose) : void
Parameters
- $onClose : Closure
read()
Reads data from the stream.
public
read([Cancellation|null $cancellation = null ][, positive-int|null $limit = null ]) : string|null
Parameters
- $cancellation : Cancellation|null = null
-
Cancel the read operation. The state in which the stream will be after a cancelled operation is implementation dependent.
- $limit : positive-int|null = null
Return values
string|null —Returns a string when new data is available or null if the stream has closed.
reference()
References the readable watcher, so the loop keeps running in case there's an active read.
public
reference() : void
Tags
setChunkSize()
public
setChunkSize(positive-int $chunkSize) : void
Parameters
- $chunkSize : positive-int
unreference()
Unreferences the readable watcher, so the loop doesn't keep running even if there are active reads.
public
unreference() : void
Tags
__clone()
protected
final __clone() : mixed
free()
Nulls reference to resource, marks stream unreadable, and succeeds any pending read with null.
private
free() : void