PHP Stream Functions

About This Index
This page is the PHP Stream Functions index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn wrappers, php://memory, contexts, filters, stream_get_contents(), and sockets on /php/stream. Use this page when you need a specific function such as stream_get_contents(), stream_context_create(), or stream_filter_append().
Start with stream_get_contents() on php://memory—then learn stream_context_create() for HTTP options, stream_filter_append() for transforms, and stream_get_meta_data() to inspect a handle.
Every Stream function in this series appears below in seven categories: buckets, contexts, filters, read & inspect, blocking / buffers / select, sockets, and wrappers & misc.
How to Call a PHP Stream Function
Stream helpers are global functions—call them directly. Open a stream, optionally attach a context or filter, then read or inspect:
$fp = fopen('php://memory', 'r+');
fwrite($fp, 'hello');
rewind($fp);
$text = stream_get_contents($fp); // string|false
$meta = stream_get_meta_data($fp); // array
fclose($fp);
$ctx = stream_context_create([
'http' => ['method' => 'GET', 'timeout' => 5],
]);
$opts = stream_context_get_options($ctx); // array
$fp = fopen('php://memory', 'r+');
stream_filter_append($fp, 'string.toupper');
fwrite($fp, 'abc');
rewind($fp);
$upper = stream_get_contents($fp); // ABC
fclose($fp);
$wrappers = stream_get_wrappers(); // array of schemes PHP Stream Functions Table
All function guides in this PHP tutorial series (47 tutorials in 7 categories).
Buckets (filter plumbing)
4 functionsLow-level data chunks used inside custom stream filters. Beginners can skip these until they write or debug a filter.
| Function | Description | Tutorial |
|---|---|---|
stream_bucket_append() | Append a bucket to a brigade for filter processing. | Try it |
stream_bucket_make_writeable() | Return a writeable bucket object from a brigade. | Try it |
stream_bucket_new() | Create a new bucket for use with a stream filter. | Try it |
stream_bucket_prepend() | Prepend a bucket to a brigade for filter processing. | Try it |
Contexts
8 functionsBuild, inspect, and change the options bag passed to fopen-family calls (HTTP headers, timeouts, and more).
| Function | Description | Tutorial |
|---|---|---|
stream_context_create() | Create a stream context from options and parameters. | Try it |
stream_context_get_default() | Retrieve the default stream context. | Try it |
stream_context_get_options() | Return the options array for a context. | Try it |
stream_context_get_params() | Return parameters (and options) for a context. | Try it |
stream_context_set_default() | Set the default stream context. | Try it |
stream_context_set_option() | Set a single option on a stream context. | Try it |
stream_context_set_options() | Set multiple options on a stream context. | Try it |
stream_context_set_params() | Set parameters on a stream context. | Try it |
Filters
5 functionsAttach, list, register, or remove filters that transform bytes as they flow through a stream.
| Function | Description | Tutorial |
|---|---|---|
stream_filter_append() | Attach a filter to the end of a stream's filter list. | Try it |
stream_filter_prepend() | Attach a filter to the start of a stream's filter list. | Try it |
stream_filter_register() | Register a user-defined stream filter class. | Try it |
stream_filter_remove() | Remove a previously attached stream filter. | Try it |
stream_get_filters() | List registered stream filter names. | Try it |
Read & inspect
9 functionsRead stream contents, copy between streams, and inspect metadata, wrappers, transports, and local/TTY status.
| Function | Description | Tutorial |
|---|---|---|
stream_copy_to_stream() | Copy data from one stream to another. | Try it |
stream_get_contents() | Read remaining data from a stream into a string. | Try it |
stream_get_line() | Read a line from a stream up to a delimiter. | Try it |
stream_get_meta_data() | Return header/meta information about a stream. | Try it |
stream_get_transports() | List registered socket transports (tcp, udp, ?). | Try it |
stream_get_wrappers() | List registered stream wrapper schemes. | Try it |
stream_is_local() | Check whether a stream or URL refers to a local resource. | Try it |
stream_isatty() | Check whether a stream is a terminal (TTY). | Try it |
stream_supports_lock() | Check whether a stream supports locking. | Try it |
Blocking / buffers / select
6 functionsControl blocking mode, chunk and buffer sizes, timeouts, and wait on multiple streams with stream_select().
| Function | Description | Tutorial |
|---|---|---|
stream_select() | Wait until one or more streams are ready to read or write. | Try it |
stream_set_blocking() | Set blocking or non-blocking mode on a stream. | Try it |
stream_set_chunk_size() | Set the chunk size used when transferring stream data. | Try it |
stream_set_read_buffer() | Set the read buffer size for a stream. | Try it |
stream_set_timeout() | Set a timeout on stream read/write operations. | Try it |
stream_set_write_buffer() | Set the write buffer size for a stream. | Try it |
Sockets
9 functionsCreate client and server sockets, enable crypto, send and receive datagrams, and shut connections down.
| Function | Description | Tutorial |
|---|---|---|
stream_socket_accept() | Accept a connection on a server socket. | Try it |
stream_socket_client() | Open a client connection to a remote socket. | Try it |
stream_socket_enable_crypto() | Turn encryption on or off for a socket stream. | Try it |
stream_socket_get_name() | Get local or remote name of a socket connection. | Try it |
stream_socket_pair() | Create a pair of connected, indistinguishable sockets. | Try it |
stream_socket_recvfrom() | Receive data from a socket, optionally with address. | Try it |
stream_socket_sendto() | Send data to a socket address. | Try it |
stream_socket_server() | Create a server socket bound to a local address. | Try it |
stream_socket_shutdown() | Shut down a full-duplex socket connection. | Try it |
Wrappers & misc
6 functionsRegister or restore wrappers, resolve include paths, and hook stream notification callbacks.
| Function | Description | Tutorial |
|---|---|---|
stream_notification_callback() | Prototype for a stream context notification callback. | Try it |
stream_register_wrapper() | Alias of stream_wrapper_register() for registering a wrapper. | Try it |
stream_resolve_include_path() | Resolve a filename against the include_path. | Try it |
stream_wrapper_register() | Register a URL wrapper implemented by a PHP class. | Try it |
stream_wrapper_restore() | Restore a previously unregistered built-in wrapper. | Try it |
stream_wrapper_unregister() | Unregister a URL wrapper. | Try it |
Frequently Asked Questions
Start with stream_bucket_append()
Open the next guide—syntax, examples, and FAQs.
7 people found this page helpful
