In PHP, stream_get_meta_data() returns an associative array of information about an open stream, such as its mode, whether it is seekable, and whether a read timed out.
The keys include timed_out, blocked, eof, wrapper_type, stream_type, mode, unread_bytes, seekable, and uri. Use it when you need to inspect how a stream behaves without reading its payload.
Syntax
Call stream_get_meta_data() with the values you need. Start with this line.
PHP
$meta = stream_get_meta_data($stream);
Call
What it does
stream_get_meta_data($stream)
Returns the metadata array for the open stream.
stream_get_meta_data($stream)["seekable"]
true when you can rewind or seek on that stream.
stream_get_meta_data($stream)["mode"]
Shows the open mode string, such as "r+" or "rb".
Metadata describes the stream handle, not the file contents. Some keys are more useful for network streams (timed_out, unread_bytes), while seekable and mode matter for files and memory streams too.
Library declarations
PHP
stream_get_meta_data(resource $stream): array
Parameters
Parameter
Description
stream
Required. The open stream resource to inspect.
Return Value
Return Value
Description
array
Associative array of stream metadata keys and values.
PHP Examples
Example 1 — Inspect a Memory Stream
Open php://memory and print a few stable metadata fields.