时时商务社区

标题: PHP file_get_contents函数读取远程数据超时的解决方法 [打印本页]

作者: yj1281    时间: 2018-2-14 05:46

            在网络状况比较差的情况下file_get_contents函数经常读取远程数据失败。
解决办法如下:
[U]复制代码[/U] 代码如下:
/*设置超时配合失败之后尝试多次读取,效果比原先好很多*/
$url = 'http://www.jb51.net';
          $opts = array(
           'http'=>array(
          'method'=>"GET",
          'timeout'=>1, //设置超时
  )
);
$context = stream_context_create($opts);
$contents = @file_get_contents($url,false,$context);
?>
            
            
您可能感兴趣的文章:
  • PHP file_get_contents 函数超时的几种解决方法
  • PHP $_FILES函数详解
  • php file_put_contents()功能函数(集成了fopen、fwrite、fclose)
  • php读取本地文件常用函数(fopen与file_get_contents)
  • PHP读取大文件的类SplFileObject使用介绍
  • php 使用file_get_contents读取大文件的方法
  • PHP移动文件指针ftell()、fseek()、rewind()函数总结
  • PHP使用fopen与file_get_contents读取文件实例分享
  • php fseek函数读取大文件两种方法
  • php使用file函数、fseek函数读取大文件效率对比分析
            




    欢迎光临 时时商务社区 (http://bbs.4435.cn/) Powered by Discuz! X3.2