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

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

 

 

posted @ 2013-10-25 13:56  午火39  阅读(525)  评论(0)    收藏  举报