PHP stream_context_create()函数的使用示例
stream_context_create()函数是用来创建打开文件的上下文件选项,用于fopen(),file_get_contents()等过程的超时设置、代理服务器、请求方式、头信息设置的特殊过程。
比如说,上篇php教程中gd库实现下载网页所有图片中,第10行:
利用了stream_context_create()设置代理服务器:
//设置代理服务器
$opts=array('http'=>array('request_fulluri'=>true));
$context=stream_context_create($opts);
$content=file_get_contents($url,false,$context);
利用了stream_context_create()设置超时时间:
$opts=array(
'http'=>array(
'method'=>"GET",
'timeout'=>60,
)
);
$context=stream_context_create($opts);
$html=file_get_contents('https://www.nhooo.com',false,$context);
热门推荐
10 五一公司放假祝福语简短
11 追星女孩的祝福语简短
12 给长辈端午祝福语 简短
13 生日祝福语有诗意简短
14 团圆日祝福语简短
15 中秋商务祝福语简短最新
16 温暖文艺简短祝福语短句
17 男孩上学祝福语简短的
18 入住酒店文案祝福语简短