Documentation

WritableResourceStream
in package
implements WritableStream, ResourceStream uses ForbidCloning, ForbidSerialization

FinalYes

Output stream abstraction for PHP's stream resources.

Table of Contents

Interfaces

WritableStream
A `WritableStream` allows writing data in chunks. Writers can wait on the returned promises to feel the backpressure.
ResourceStream

Constants

LARGE_CHUNK_SIZE  = 128 * 1024

Properties

$callbackId  : string
$chunkSize  : positive-int|null
$errorHandler  : callable(): bool
$onClose  : DeferredFuture
$resource  : resource|null
$writable  : bool
$writes  : SplQueue<string|int, Suspension|null}>

Methods

__construct()  : mixed
__destruct()  : mixed
__serialize()  : never
__unserialize()  : never
close()  : void
Closes the stream forcefully. Multiple `close()` calls are ignored.
end()  : void
Closes the stream after all pending writes have been completed. Optionally writes a final data chunk before.
getResource()  : resource|object|null
isClosed()  : bool
Returns whether this resource has been closed.
isWritable()  : bool
onClose()  : void
Registers a callback that is invoked when this resource is closed.
reference()  : void
References the writable watcher, so the loop keeps running in case there's a pending write.
setChunkSize()  : void
unreference()  : void
Unreferences the writable watcher, so the loop doesn't keep running even if there are pending writes.
write()  : void
Writes data to the stream.
__clone()  : mixed
free()  : void
Nulls reference to resource, marks stream unwritable, and fails any pending write.

Constants

Properties

Methods

__construct()

public __construct(resource $stream[, positive-int|null $chunkSize = null ]) : mixed
Parameters
$stream : resource

Stream resource.

$chunkSize : positive-int|null = null

Chunk size per fwrite() operation.

__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

end()

Closes the stream after all pending writes have been completed. Optionally writes a final data chunk before.

public end() : void

getResource()

public getResource() : resource|object|null
Return values
resource|object|null

Stream resource or null if end() has been called or the stream closed.

isClosed()

Returns whether this resource has been closed.

public isClosed() : bool
Return values
bool

true if closed, otherwise false.

isWritable()

public isWritable() : bool
Return values
bool

A stream may no longer be writable if it is closed or ended using end().

onClose()

Registers a callback that is invoked when this resource is closed.

public onClose(Closure $onClose) : void
Parameters
$onClose : Closure

setChunkSize()

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

write()

Writes data to the stream.

public write(string $bytes) : void
Parameters
$bytes : string

Bytes to write.

Tags
throws
ClosedException

If the stream has already been closed.

free()

Nulls reference to resource, marks stream unwritable, and fails any pending write.

private free() : void

        
On this page

Search results