Example 1 — Set One HTTP Option
Create an empty context, set user_agent, then read it back with get_options().
<?php
$ctx = stream_context_create();
$ok = stream_context_set_option($ctx, "http", "user_agent", "Single/1");
$opts = stream_context_get_options($ctx);
echo $ok ? "ok" : "fail", PHP_EOL;
echo $opts["http"]["user_agent"], PHP_EOL; How It Works
- An empty context is created first.
- set_option() stores http/user_agent in one call.
- The boolean return value is true on success.
- get_options() proves the value is Single/1.

