stream_context_create
创建资源流上下文
&reftitle.description;
resourcestream_context_create
arraynulloptions&null;
arraynullparams&null;
创建并返回一个资源流上下文,该资源流中包含了 options 中提前设定的所有参数的值。
&reftitle.parameters;
options
必须是一个二维关联数组或 &null;,二维关联数组格式如下:$arr['wrapper']['option'] = $value。请参考
上下文(Context)选项 中可用的封装协议和选项列表。
默认为 &null;。
params
必须是 $arr['parameter'] = $value 格式的关联数组或 &null;。
请参考 上下文(Context)参数 里的标准资源流参数列表。
&reftitle.returnvalues;
上下文资源流,类型为 resource 。
&reftitle.changelog;
&Version;
&Description;
8.0.0
现在 options 和 params 可以为 null。
&reftitle.examples;
使用 stream_context_create
[
'method' => "GET",
// 使用 CRLF \r\n 分隔多个 header
'header' => "Accept-language: en\r\n" .
"Cookie: foo=bar",
]
];
$context = stream_context_create($opts);
/* 包含上面的 header 头,向 www.example.com
发送 HTTP 请求 */
$fp = fopen('http://www.example.com', 'r', false, $context);
fpassthru($fp);
fclose($fp);
?>
]]>
&reftitle.seealso;
stream_context_set_option
支持的封装协议列表()
上下文选项()