首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

stream_context_get_default

(PHP 5 >= 5.1.0, PHP 7)

stream_context_get_default - 检索默认流上下文

描述

代码语言:javascript
复制
resource stream_context_get_default ([ array $options ] )

返回在没有上下文参数的情况下调用文件操作(fopen(),file_get_contents()等)时使用的默认流上下文。可以使用与stream_context_create()相同的语法,使用此函数可选地指定默认上下文的选项。

参数

options options必须是$ arr'wrapper'= $ value格式的关联数组的关联数组。

注意:从PHP 5.3.0开始,可以使用stream_context_set_default()函数来设置默认上下文。

返回值

流上下文资源。

示例

示例#1使用stream_context_get_default()

代码语言:javascript
复制
<?php
$default_opts?=?array(
??'http'=>array(
????'method'=>"GET",
????'header'=>"Accept-language:?en\r\n"?.
??????????????"Cookie:?foo=bar",
????'proxy'=>"tcp://10.54.1.39:8000"
??)
);


$alternate_opts?=?array(
??'http'=>array(
????'method'=>"POST",
????'header'=>"Content-type:?application/x-www-form-urlencoded\r\n"?.
??????????????"Content-length:?"?.?strlen("baz=bomb"),
????'content'=>"baz=bomb"
??)
);

$default?=?stream_context_get_default($default_opts);
$alternate?=?stream_context_create($alternate_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');

/*?Sends?a?POST?request?directly?to?www.example.com
?*?Using?context?options?specified?in?$alternate_opts
?*/
readfile('http://www.example.com',?false,?$alternate);

?>

另请参阅

  • stream_context_create() - 创建一个流上下文

← stream_context_create

stream_context_get_options →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com