php教程

file_get_contents函数访问大文件超时解决方法

php教程 51源码 05-08 人阅读

file_get_contents函数在访问大文件时,会报错504超时,下面分享下我的站长站的解决方法。

$opts = array(
'http'=>array(
'method'=>"GET",
'timeout'=>60,
)
);
 
$context = stream_context_create($opts);
 
$html =file_get_contents('https://www.51yma.cn', false, $context);

这样,file_get_contents获取数据时,超出60秒将会自动退出。


标签 PHP函数