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

stream_context_set_default · Set the default stream context

· 52CE 我爱测

stream_context_set_default — Set the default stream context

stream_context_set_default

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

stream_context_set_default — Set the default stream context

说明

function stream_context_set_default(array $options): resource

Set the default stream context which will be used whenever file operations (fopen(), file_get_contents(), etc...) are called without a context parameter. Uses the same syntax as stream_context_create().

参数

options

The options to set for the default context.

注意:

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

返回值

Returns the default stream context.

示例

示例 #1 stream_context_set_default() example

<?php
$default_opts = [
  'http' => [
    'method' => "GET",
    'header' => "Accept-language: en\r\n" .
                "Cookie: foo=bar",
    'proxy'  => "tcp://10.54.1.39:8000",
  ]
];

$default = stream_context_set_default($default_opts);

/* Sends a regular GET request to proxy server at 10.54.1.39
 * For www.example.com using context options specified in $default_opts
 */
readfile('http://www.example.com');
?>

参见

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

资料来源与适用范围

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

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

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