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);
热门推荐
1 训练狗狗搜寻
2 如何训练狗狗装死
3 狗狗训练书
6 怎么训练狗狗拜年
8 狗狗训练游戏
10 狗狗嗅觉训练
11 怎么训练狗狗在笼子里不叫
12 怎么训练狗狗站立走路
13 怎么训练狗狗在马桶上
14 狗狗尿尿怎么训练
15 训练狗狗用品
16 泰迪狗狗的训练方法大小便
17 训练狗狗可以打吗
18 王曼丽的狗狗训练