stream_context_set_option

Sets an option for a stream/wrapper/context

Description

bool stream_context_set_option(
    resource $stream_or_context,
    string $wrapper,
    string $option_name,
    mixed $value
)

The following alternative signature is deprecated as of PHP 8.4.0, use stream_context_set_options instead.

bool stream_context_set_option(resource $stream_or_context, array $options)

Sets an option on the specified context. value is set to option for wrapper

Parameters

stream_or_context

The stream or context resource to apply the options to.

wrapper

The name of the wrapper (which may be different than the protocol). Refer to context options and parameters for a listing of stream options.

option_name

The name of the option.

value

The value of the option.

options

The options to set for stream_or_context.

Note:

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

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

Return Values

Returns true on success or false on failure.

Errors/Exceptions

Throws a TypeError if stream_or_context is not a valid stream or stream context resource.

Throws a ValueError if option_name or value is missing when wrapper is a string, or if either of them is given along with an options array.

Throws a ValueError if options is not of the form $arr['wrapper']['option'] = $value, that is, if one of its elements is not an array or has an integer key.

Changelog

Version Description
8.4.0 The alternative 2-parameter signature is now deprecated. Use stream_context_set_options instead.
8.0.9 Now throws a ValueError if value is not provided when wrapper is a string.
8.0.0 Now throws a TypeError if stream_or_context is not a valid stream or stream context resource. Previously, an E_WARNING was raised and false was returned.
8.0.0 Now throws a ValueError if options is not of the expected form. Previously, an E_WARNING was raised.
8.0.0 Now throws a ValueError if option_name is null when wrapper is a string, or if option_name or value is given along with an options array. Previously, an E_WARNING was raised and false was returned, except when option_name was null and value was given, which was accepted.