PHP file_get_contents函数读取远程数据超时的解决方法_PHP教程

WBOY
Release: 2016-07-13 09:53:43
Original
833 people have browsed it

PHP file_get_contents函数读取远程数据超时的解决方法

   这篇文章主要介绍了PHP file_get_contents函数读取远程数据超时的解决方法,本文直接给出解决方法代码,需要的朋友可以参考下

  在网络状况比较差的情况下file_get_contents函数经常读取远程数据失败。

  解决办法如下:

   代码如下:

  /*设置超时配合失败之后尝试多次读取,效果比原先好很多*/

  $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);

  ?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1000091.htmlTechArticlePHP file_get_contents函数读取远程数据超时的解决方法 这篇文章主要介绍了PHP file_get_contents函数读取远程数据超时的解决方法,本文直接给出解...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!