Documentation

ReadableResourceStream
in package
implements ReadableStream, ResourceStream, IteratorAggregate uses ReadableStreamIteratorAggregate, ForbidCloning, ForbidSerialization

FinalYes

Readable stream abstraction for PHP's stream resources.

Tags
implements

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

Properties

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
throws
Error

If an invalid stream or parameter has been passed.

__unserialize()

public final __unserialize(array<string|int, mixed> $data) : never
Parameters
$data : array<string|int, mixed>
Return values
never

close()

Closes the stream forcefully. Multiple `close()` calls are ignored.

public close() : void

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.

setChunkSize()

public setChunkSize(positive-int $chunkSize) : void
Parameters
$chunkSize : positive-int

free()

Nulls reference to resource, marks stream unreadable, and succeeds any pending read with null.

private free() : void

        
On this page

Search results