Using the PHP Function Stream_Context_Create() to Create Streams
Streams are one of the more little known powerful resources that PHP provides. They are responsible for doing things like reading from a website and posting to it, processing compressed files line by line, and even writing to disk. Those tasks are typically done using wrappers (similar to how cURL is used for HTTP requests).
In PHP, there are several wrapper libraries built into it by default (see List of Supported Protocols/Wrappers). Custom wrappers can be created and added either within a script using stream_wrapper_register() or directly from an extension. Then, these wrappers can be used to do all sorts of stream related tasks.
A context is a set of parameters and wrapper specific options that enhance or change the behavior of a stream. Contexts are created using the stream_context_create() function and can be passed to most filesystem related stream creation functions such as fopen(), file(), or file_get_contents().
This example shows you how to use a stream context to pass multiple HTTP options to file_get_contents so that it can send an HTTP POST request. The context also has a ignore_errors option which will suppress any errors that file_get_contents might encounter while fetching the URL's content.
The resulting stream is a sequenced two-way byte stream that can be used to transmit data from the client to the server or vice versa. You can then read the contents of that stream in whatever manner you want. The memory footprint for this kind of stream is extremely low compared to the traditional'read/write' pattern that most other types of streams have to work with.