Example 1 — Create a Context and Read Its Options
Build a context with a sample HTTP user agent, then print the stored options. No network call is made.
<?php
$options = [
"http" => [
"method" => "GET",
"user_agent" => "CodeToFun/1",
],
];
$ctx = stream_context_create($options);
$stored = stream_context_get_options($ctx);
echo $stored["http"]["method"], PHP_EOL;
echo $stored["http"]["user_agent"], PHP_EOL; How It Works
- The $options array uses the nested wrapper/option shape.
- stream_context_create() turns that array into a context resource.
- stream_context_get_options() reads the options back for display.
- We print method and user_agent to confirm they were stored.

