在用file_get_contents函数的时候,我写了如下的例子:
文件名字:test.php
<?
$test = file_get_contents('http://www.tudou.com/playlist/playindex.do?lid=8294366');
echo $test;
?>当我重复刷新test.php页面的时候。有时候能读到这个视频的内容。但是有的时候提示错误:
Warning: file_get_contents(http://www.tudou.com/playlist/playindex.do?lid=8294366) [function.file-get-contents]: failed to open stream: HTTP request failed!

解决方案 »

  1.   

    把file_get_contents放在循环中多重试几次
    <?php
    /*设置超时配合失败之后尝试多次读取*/
              $opts = array( 
               'http'=>array( 
             'method'=>"GET", 
             'timeout'=>1, //设置超时

    ); 
    $context = stream_context_create($opts); 
    $cnt=1; //最多尝试10次读取
              while(($contents = @file_get_contents("$url",false,$context)) === false && $cnt <= 10  )
    $cnt++;
    ?>
    超时和重试,这是网络传输的常用方法
      

  2.   

    And ping the ip , check the timeout is service ...