stream_context_create()
stream_context_create() — Creates a stream context.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Creates and returns a stream context with any options supplied in options preset.
Signature
stream_context_create(?array $options = null, ?array $params = null): resource
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $options | ?array | Must be an associative array of associative arrays in the format $arr['wrapper']['option'] = $value, or null. Refer to context options for a list of available wrappers and options. |
| $params | ?array | Must be an associative array in the format $arr['parameter'] = $value, or null. Refer to context parameters for a listing of standard stream parameters. |
Return value
A stream context resource.
Example
A runnable snippet:
$opts = [ 'http' => [ 'method' => "GET", // Use CRLF \r\n to separate multiple headers 'header' => "Accept-language: en\r\n" . "Cookie: foo=bar", ] ]; $context = stream_context_create($opts); /* Sends an http request to www.example.com with additional headers shown above */ $fp = fopen('http://www.example.com', 'r', false, $context); fpassthru($fp); fclose($fp);
Changelog
| Version | Change |
|---|---|
| 8.0.0 | options and params are now nullable. |
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page stream_context_create() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.