PHP streams are a single way to read and write many kinds of data: local files, HTTP responses, in-memory buffers, and network sockets. A wrapper is the scheme that tells PHP how to open that resource (file://, http://, php://, and others). List them with stream_get_wrappers().
They let you treat files, memory, HTTP, and sockets with the same read/write tools, so beginner code can grow from php://memory demos to real network work without learning a new API each time.
Contexts are not filters.
A context sets how a wrapper opens a resource (timeouts, HTTP headers). A filter changes the bytes as they pass through an already-open stream. Learn both: stream_context_create() and stream_filter_append().
Syntax
PHP Syntax
The usual pattern: open a stream, optionally attach a context or filter, then read or write:
Low-level filter plumbing; beginners usually start with built-in filters first
Contexts, filters, and sockets
Pass a context as the last argument to fopen(), file_get_contents(), and similar calls. Filters stack on an open stream and can be removed with stream_filter_remove(). For network work, open a client with stream_socket_client(), optionally set a timeout with stream_set-timeout(), and use stream_select() when you wait on more than one socket. Custom filter authors work with buckets via stream_bucket_new() and friends.
Map
Function Groups at a Glance
The Stream section is one family with seven jobs. Use this map to pick the right group before you open a function page:
Group
Typical job
Start here
Buckets
Low-level chunks used inside custom stream filters
Neighboring tutorials that often sit next to this work: Output Control for catching echoed text before it reaches a stream, Filesystem for fopen() and file helpers, Strings for editing bytes you read from a stream, and Variables for storing context arrays and captured text.
Code
PHP Examples
Three short, offline-safe scripts: a memory stream with stream_get_contents(), an HTTP-style context you can inspect without a network call, and a string.toupper filter. Each block includes a fixed View Output panel.
Example 1 — php://memory and stream_get_contents()
Open an in-memory stream, write two lines, rewind, then read everything with stream_get_contents().
stream_filter_append() attaches string.toupper so writes (or reads, depending on filter mode) are transformed.
We write lowercase text, rewind, then stream_get_contents() returns the uppercase result.
stream_filter_remove() detaches the filter resource when you no longer need it.
stream_get_filters() lists built-in and registered filter names on this PHP build.
Custom filters use bucket helpers; start with built-in filters before writing your own.
Continue
Next: PHP Stream Functions Index
After you know what wrappers are, how php://memory works, how contexts carry HTTP options, how filters transform bytes, and how sockets fit in, open the functions index for all 47 guides.
A stream is a flow of data you can read from or write to with the same helpers used for files. Files, HTTP responses, memory buffers (php://memory), and sockets can all appear as streams. Wrappers give each kind of resource a scheme name such as file://, http://, or php://.
A wrapper teaches PHP how to open a particular kind of resource. Built-in wrappers include file, http, https, ftp, php, data, and more. stream_get_wrappers() lists the ones available on your install. You can also register a custom wrapper with stream_wrapper_register().
php://memory is an in-memory stream you open with fopen(). You can fwrite() into it, rewind(), then read with fread() or stream_get_contents() without touching the disk. It is ideal for offline demos and for building temporary binary or text payloads.
A context is an options bag you pass to fopen(), file_get_contents(), and similar calls. Create one with stream_context_create(). For HTTP you can set method, header, timeout, and other http wrapper options without changing how you read the response.
Filters transform data as it flows through a stream. Attach one with stream_filter_append() or stream_filter_prepend(). Built-in filters include string.toupper, string.tolower, and convert.* helpers. Custom filters use buckets (stream_bucket_*) under the hood.
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. Open the functions index for all 47 guides.