PHP Stream Functions

Beginner
5 min read
Updated: Nov 2026
47 function guides
Function index

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().

Beginner path.

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.

Forty-seven guides.

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:

PHP
$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 functions

Low-level data chunks used inside custom stream filters. Beginners can skip these until they write or debug a filter.

FunctionDescriptionTutorial
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 functions

Build, inspect, and change the options bag passed to fopen-family calls (HTTP headers, timeouts, and more).

FunctionDescriptionTutorial
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 functions

Attach, list, register, or remove filters that transform bytes as they flow through a stream.

FunctionDescriptionTutorial
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 functions

Read stream contents, copy between streams, and inspect metadata, wrappers, transports, and local/TTY status.

FunctionDescriptionTutorial
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 functions

Control blocking mode, chunk and buffer sizes, timeouts, and wait on multiple streams with stream_select().

FunctionDescriptionTutorial
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 functions

Create client and server sockets, enable crypto, send and receive datagrams, and shut connections down.

FunctionDescriptionTutorial
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 functions

Register or restore wrappers, resolve include paths, and hook stream notification callbacks.

FunctionDescriptionTutorial
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

They are the built-in PHP functions for working with streams: create contexts with stream_context_create(), attach filters with stream_filter_append(), read with stream_get_contents() and stream_get_line(), inspect with stream_get_meta_data(), wait with stream_select(), talk to sockets with stream_socket_client(), and register wrappers with stream_wrapper_register(). This index links to a full tutorial for each one.
The Stream page teaches the ideas: what wrappers are, php://memory with fopen(), HTTP contexts, filters, stream_get_contents(), and a sockets overview, with three fixed offline examples. This index lists every function tutorial so you can open stream_bucket_append(), stream_get_contents(), stream_context_create(), and the rest.
Start with stream_get_contents() on a php://memory handle so you can read a whole stream into a string. Then learn stream_context_create() for HTTP options, stream_filter_append() for transforms, and stream_get_meta_data() to inspect a handle. The sidebar begins with stream_bucket_append() because of alphabetical order.
A context is an options bag for how a wrapper opens a resource (for example HTTP method and headers). A filter transforms bytes on an already-open stream. Use stream_context_create() for options and stream_filter_append() for transforms.
Usually not. Buckets (stream_bucket_append(), stream_bucket_new(), and related helpers) are the plumbing inside custom stream filters. Learn built-in filters first; open the bucket guides when you write or debug a custom filter.
Open stream_bucket_append() next (it is the first guide in sidebar order), or jump to stream_get_contents() and stream_context_create() if you want the everyday read and HTTP-options patterns first. Read PHP Stream if the groups below still feel unfamiliar.

Start with stream_bucket_append()

Open the next guide—syntax, examples, and FAQs.

stream_bucket_append() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

7 people found this page helpful