PHP stream_context_create()函数的使用示例
程序员文章站
2022-03-31 23:04:19
stream_context_create()函数是用来 创建打开文件的上下文件选项 ,用于fopen(),file_get_contents()等过程的超时设置、代理服务...
stream_context_create()函数是用来 创建打开文件的上下文件选项 ,用于fopen(),file_get_contents()等过程的超时设置、代理服务器、请求方式、头信息设置的特殊过程。
比如说,上篇php教程中中,第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('//www.jb51.net', false, $context);
推荐阅读
-
php实现的程序员使用的web简易采集器V2版
-
php简单对象与数组的转换函数代码(php多层数组和对象的转换)_php技巧
-
php中的四舍五入函数代码(floor函数、ceil函数、round与intval),ceilintval
-
php array_search() 函数使用
-
[开心学PHP100天(七)]精讲PHP构造函数:父亲和儿子的恩恩怨怨_PHP教程
-
解析PHP自带的进位制之间的转换函数
-
PHP获取ip对应地区和使用网络类型的方法
-
PHP soap拓展的使用
-
WordPress开发中的get_post_custom()函数使用解析,wordpressgetpost
-
php遍历目录下所有文件的函数