PHP file_get_contents函数读取远程数据超时的解决方法
发布:smiling 来源: PHP粉丝网 添加日期:2021-05-26 21:41:48 浏览: 评论:0
这篇文章主要介绍了PHP file_get_contents函数读取远程数据超时的解决方法,本文直接给出解决方法代码,需要的朋友可以参考下。
在网络状况比较差的情况下file_get_contents函数经常读取远程数据失败。
解决办法如下:
- /*设置超时配合失败之后尝试多次读取,效果比原先好很多*/
 - $url = 'https://www.phpfensi.com';
 - $opts = array(
 - 'http'=>array(
 - 'method'=>"GET",
 - 'timeout'=>1, //设置超时
 - )
 - );
 - $context = stream_context_create($opts);
 - $contents = @file_get_contents($url,false,$context);
 - ?>
 
Tags: file_get_contents
相关文章
- ·php中file_get_contents获取网页乱码解决办法(2013-12-05)
 - ·php file_get_contents与curl()函数对比(2014-01-16)
 - ·php file_get_contents数据采集与常用见问题解决(2014-01-16)
 - ·php中常用文件操作读写函数介绍(2014-03-28)
 - ·php中curl和file_get_content函数抓页面对比(2014-06-21)
 - ·php中file_get_contents和curl两个函数用法(2014-08-02)
 - ·file_get_contents实现数据Post数据方法(2014-08-04)
 - ·file_get_contents获取远程网页内容函数(2014-09-20)
 - ·php中file_get_contents代替使用curl示例(2015-04-09)
 - ·PHP CURL或file_get_contents获取网页标题的代码(2015-04-10)
 - ·php中file_get_contents函数高级用法(2015-04-15)
 - ·php中file_get_contents()函数用法实例(2021-11-10)
 
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
 - PHP新手上路(一)(7)
 - 惹恼程序员的十件事(5)
 - PHP邮件发送例子,已测试成功(5)
 - 致初学者:PHP比ASP优秀的七个理由(4)
 - PHP会被淘汰吗?(4)
 - PHP新手上路(四)(4)
 - 如何去学习PHP?(2)
 - 简单入门级php分页代码(2)
 - php中邮箱email 电话等格式的验证(2)
 
