源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP stream_context_create()函数的使用示例

  • 时间:2020-04-01 04:55 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP stream_context_create()函数的使用示例
stream_context_create()函数是用来 创建打开文件的上下文件选项 ,用于fopen(),file_get_contents()等过程的超时设置、代理服务器、请求方式、头信息设置的特殊过程。 比如说,上篇php教程中[url=http://www.1sucai.cn/article/65928.htm]gd库实现下载网页所有图片[/url]中,第10行: 利用了stream_context_create()设置代理服务器:
[u]复制代码[/u] 代码如下:
//设置代理服务器 $opts = array('http'=>array('request_fulluri'=>true)); $context = stream_context_create($opts); $content = file_get_contents($url,false,$context);
利用了stream_context_create()设置超时时间:
[u]复制代码[/u] 代码如下:
 $opts = array(     'http'=>array(     'method'=>"GET",     'timeout'=>60,   ) ); $context = stream_context_create($opts); $html =file_get_contents('http://www.1sucai.cn', false, $context);
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部