在网络状况比较差的情况下file_get_contents函数经常读取远程数据失败。
解决办法如下:
<br />/*设置超时配合失败之后尝试多次读取,效果比原先好很多*/<br />$url = 'http://www.gaodaima.com';<br /> $opts = array( <br /> 'http'=>array( <br /> 'method'=>"GET", <br /> 'timeout'=>1, //设置<mark>(本文来)源gaodaimacom搞#^代%!码&网(</mark><pre>搞gaodaima代码
超时
)
);
$context = stream_context_create($opts);
$contents = @file_get_contents($url,false,$context);
?>