php file_get_contents计时读取一个文件/页面 防止读取不到内容

$url = 'http://www.baidu.com/index.php';
$opts = array(
        'http' => array(
            'method' => 'GET',
            'header' => 'Accept-language: en\r\n'.'Cookie: foo=bar\r\n',
            'timeout'=> 20
        )    
    );
    $context = stream_context_create($opts);
    $t     = 0;
    while($t < 4 && ($getcontent=@file_get_contents($url)) === FAlse )
    {
        $t++;
    }
var_dump($getcontent);

 

 

相关文章:

  • 2021-11-11
  • 2021-10-03
  • 2021-12-28
  • 2021-07-04
  • 2021-06-01
  • 2021-05-18
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案