PHP stream_context_create()函数的使用示例

Nadia ·
更新时间:2024-09-20
· 678 次阅读

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.jb51.net', false, $context);

您可能感兴趣的文章:PHP中的流(streams)浅析PHP Streams(流)详细介绍及使用PHP中的Streams详细介绍PHP Wrapper在SAE上的应用方法php常用Stream函数集介绍php stream_get_meta_data返回值PHP Stream_*系列函数PHP使用stream_context_create()模拟POST/GET请求的方法深入理解PHP中的Streams工具PHP stream_context_create()作用和用法分析PHP流Streams、包装器wrapper概念与用法实例详解



stream create 示例 函数 context PHP

需要 登录 后方可回复, 如果你还没有账号请 注册新账号