2345技术员联盟

stream_context_create()函数的使用方法

  • 来源:电脑技术网 原创
  • 时间:2015-05-13
  • 阅读:
  • 本文标签:PHP

stream_context_create()函数是用来 创建打开文件的上下文件选项 ,用于fopen(),file_get_contents()等过程的超时设置、代理服务器、请求方式、头信息设置的特殊过程。

比如说,上篇php教程中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('http://www.it892.com', false, $context);
本文来自电脑技术网www.it892.com),转载本文请注明来源.
本文链接:http://www.it892.com/content/web/php/051360302015.html
推荐阅读
热点排行
无觅相关文章插件,快速提升流量