WritableResourceStream
in package
implements
WritableStream, ResourceStream
uses
ForbidCloning, ForbidSerialization
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
LARGE_CHUNK_SIZE
private
mixed
LARGE_CHUNK_SIZE
= 128 * 1024
Properties
$callbackId
private
string
$callbackId
$chunkSize
private
positive-int|null
$chunkSize
= null
$errorHandler read-only
private
callable(): bool
$errorHandler
$onClose read-only
private
DeferredFuture
$onClose
$resource
private
resource|null
$resource
$writable
private
bool
$writable
= true
$writes read-only
private
SplQueue<string|int, Suspension|null}>
$writes
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.
__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
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
reference()
References the writable watcher, so the loop keeps running in case there's a pending write.
public
reference() : void
Tags
setChunkSize()
public
setChunkSize(positive-int $chunkSize) : void
Parameters
- $chunkSize : positive-int
unreference()
Unreferences the writable watcher, so the loop doesn't keep running even if there are pending writes.
public
unreference() : void
Tags
write()
Writes data to the stream.
public
write(string $bytes) : void
Parameters
- $bytes : string
-
Bytes to write.
Tags
__clone()
protected
final __clone() : mixed
free()
Nulls reference to resource, marks stream unwritable, and fails any pending write.
private
free() : void