大网数据广告活动
PHP 语言与运行手册

stream_context_set_options · Sets options on the specified context

· 52CE 我爱测

stream_context_set_options — Sets options on the specified context

stream_context_set_options

(PHP 8 >= 8.3.0)

stream_context_set_options — Sets options on the specified context

说明

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

Sets options on the specified context.

参数

context

The stream or context resource to apply the options to.

options

The options to set for context.

注意:

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.

返回值

成功时返回 true, 或者在失败时返回 false。

示例

示例 #1 stream_context_set_options() example

<?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));
?>

以上示例会输出:

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

参见

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。