php8.5
Home/ Manual/ stream / functions/ stream_context_set_options

stream_context_set_options

PHP function Edit on GitHub ✎

(PHP 8 >= 8.3.0)

Sets options on the specified context

Description

stream_context_set_options(resource $context, array $options): true

Sets options on the specified context.

Parameters

context

The stream or context resource to apply the options to.

options

The options to set for context.

Note

options must be an associative Array of associative arrays in the format $array['wrapper']['option'] = $value.

Refer to context options and parameters for a listing of stream options.

Return Values

Success

Examples

stream_context_set_options() example

php
<?php

$context = stream_context_create();

$options = [
    'http' => [
        'protocol_version' => 1.1,
        'user_agent' => 'PHPT Agent',
    ],
];

stream_context_set_options($context, $options);
var_dump(stream_context_get_options($context));
?>

The above example will output:

output
array(1) {
  ["http"]=>
  array(2) {
    ["protocol_version"]=>
    float(1.1)
    ["user_agent"]=>
    string(10) "PHPT Agent"
  }
}

See Also

Source: reference/stream/functions/stream-context-set-options.xml · from the official PHP manual (php/doc-en)