Stream
MMO\core\server · 1 symbol · generated 30 Sep 2026
Stream
Stream.php:13PHP stream implementation.
- Namespace
MMO\core\server- Implements
StreamInterface, iRenderable, iSerializable
Index
| stream | ||
| close() | StreamInterface::close Detaches and closes the underlying resource -- except STDIN/STDOUT/STDERR when running from the CLI, which are left open since they're process-wide and shared (closing them h… | |
| debugName() | ||
| detach() | StreamInterface::detach | |
| Empty() static | Get an empty stream WARNING: don't write in it as this instance is shared by whomever call this function | |
| eof() | StreamInterface::eof | |
| File($filename, $mode) static | Get a Stream on a file | |
| getContents() | StreamInterface::getContents Reads from the current position to the end (unlike render, does NOT rewind first or restore position). | |
| getContentType($single) | NOTE: the return type used to be declared string|array even though this method can return false (when the stream has no usable URI) -- harmless in practice (PHP's weak typing silently coerces t… | |
| getMetadata($key) | StreamInterface::getMetadata | |
| getResource() | ||
| getSize() | StreamInterface::getSize | |
| getUri() | ||
| isReadable() | StreamInterface::isReadable | |
| isSeekable() | StreamInterface::isSeekable | |
| isWritable() | StreamInterface::isWritable | |
| read($length) | StreamInterface::read | |
| render($opts) | ||
| rewind() | StreamInterface::rewind Shorthand for seek(0). | |
| seek($offset, $whence) | StreamInterface::seek | |
| serialize($path, $serializer) | ||
| STDERR() static | ||
| STDIN() static | ||
| STDOUT() static | ||
| tell() | StreamInterface::tell | |
| TEMP() static | Get a new stream backed by php://temp (memory, spilling to a temp file past ~2MB -- unlike Text, which is always pure memory). | |
| Text($text) static | Get a Stream on a text | |
| unserialize($data, $path, $instances) | ||
| write($text) | StreamInterface::write Writes the full string, looping over fwrite (which can write fewer bytes than requested in one call, e.g. | |
| __construct($stream) | Constructor | |
| __destruct() | Destructor. Closes the stream | |
| __toString() | StreamInterface::__toString |
Properties1
stream
Methods31
close()
Stream.php:230StreamInterface::close Detaches and closes the underlying resource -- except STDIN/STDOUT/STDERR when running from the CLI, which are left open since they're process-wide and shared (closing them here would break anything else still using them, e.g. later STDOUT calls).
| returns | void |
debugName()
Stream.php:32| returns | string | the underlying resource's filename (basename only), or the class name if the stream is detached. |
detach()
Stream.php:242StreamInterface::detach
| returns | mixed | the raw resource (now detached from this Stream instance -- the caller owns it and must close it themselves), or null if the stream was already detached. |
Empty()
staticStream.php:185Get an empty stream WARNING: don't write in it as this instance is shared by whomever call this function
| returns | self |
eof()
Stream.php:297StreamInterface::eof
| returns | bool | true if the stream is detached, or if its read pointer is at the end. |
File($filename, $mode)
staticStream.php:153Get a Stream on a file
getContents()
Stream.php:323StreamInterface::getContents Reads from the current position to the end (unlike render, does NOT rewind first or restore position).
| returns | string | the remaining stream content from the current position onward. |
| throws | if the stream is detached, or reading fails. |
getContentType($single)
Stream.php:62NOTE: the return type used to be declared string|array even though this method can return false (when the stream has no usable URI) -- harmless in practice (PHP's weak typing silently coerces that false into an empty string for a string-compatible return type, and every real caller checks the result loosely, e.g.
getMetadata($key)
Stream.php:216StreamInterface::getMetadata
| $key = null | a specific metadata key (e.g. 'uri', 'mode', 'seekable'), or null for all of it. | |
| returns | mixed | the requested value (null if $key doesn't exist), the full metadata array if $key is null, or ([]/null respectively) if the stream is detached. |
getResource()
Stream.php:40| returns | the raw underlying PHP stream resource (null if detach was called). |
getSize()
Stream.php:257StreamInterface::getSize
getUri()
Stream.php:48| returns | string | the underlying resource's full path/URI (e.g. /tmp/foo.txt, php://memory), or '' if it has none. |
isReadable()
Stream.php:271StreamInterface::isReadable
isSeekable()
Stream.php:289StreamInterface::isSeekable
isWritable()
Stream.php:280StreamInterface::isWritable
read($length)
Stream.php:366StreamInterface::read
| $length | int | maximum number of bytes to read (may return fewer, e.g. near EOF). |
| returns | string | up to $length bytes read from the current position ('' if $length is 0). |
| throws | if $length is negative. | |
| throws | if the stream is non-readable (isReadable), or reading fails. |
render($opts)
Stream.php:83- See
iRenderable::renderReads the full stream content, restoring the original position afterward (if seekable) so the stream can still be read again normally.
| $opts = [] | array | unused. |
| returns | string | the stream's full content, or an error message string if reading fails. |
rewind()
Stream.php:339StreamInterface::rewind Shorthand for seek(0).
| returns | void | |
| throws | if the stream is not seekable, or the seek fails. |
seek($offset, $whence)
Stream.php:350StreamInterface::seek
- See
fseek
| $offset | int | the position to seek to (interpreted per $whence). |
| $whence = SEEK_SET | int | \SEEK_SET (from the start, default), \SEEK_CUR (from the current position), or \SEEK_END (from the end). |
| returns | void | |
| throws | if the stream is not seekable (isSeekable), or the seek fails. |
serialize($path, $serializer)
Stream.php:108- See
iSerializable::serializeSerializes as the resource's URI and open mode, sounserializecan reopen an equivalent stream -- NOTE: the actual stream content is NOT captured (aphp://memorystream, for example, cannot be reopened by URI and will come back empty).
STDERR()
staticStream.php:140| returns | self | a shared instance wrapping the process's STDERR (or php://stderr when not running from the CLI). |
STDIN()
staticStream.php:133| returns | self | a shared instance wrapping the process's STDIN (or php://input when not running from the CLI). |
STDOUT()
staticStream.php:126| returns | self | a shared instance wrapping the process's STDOUT (or php://output when not running from the CLI). |
tell()
Stream.php:306StreamInterface::tell
| returns | int | the current read/write pointer position, in bytes from the start. |
| throws | if the stream is detached, or the position can't be determined. |
TEMP()
staticStream.php:177Get a new stream backed by php://temp (memory, spilling to a temp file past ~2MB -- unlike Text, which is always pure memory).
| returns | self |
Text($text)
staticStream.php:166Get a Stream on a text
unserialize($data, $path, $instances)
Stream.php:120- See
iSerializable::unserializeReopens the stream from the [uri, mode] pair produced byserialize.
write($text)
Stream.php:385StreamInterface::write Writes the full string, looping over fwrite (which can write fewer bytes than requested in one call, e.g. on a full buffer) until everything has been written.
| $text | string | |
| returns | int | the number of bytes written (always strlen($text) on success). |
| throws | if the stream is non-writable (isWritable), or a write call fails. |
__construct($stream)
Stream.php:23Constructor
| $stream | the resource to use as a StreamInterface. If string, will be converted to a stream in memory | |
| throws | if the stream is not a resource |
__destruct()
Stream.php:197Destructor. Closes the stream
__toString()
Stream.php:205StreamInterface::__toString