PHP的file_get_contents函数的参数问题

2025-02-28 14:47:07
推荐回答(1个)
回答1:

set_time_limit只是设置你的PHP程序的超时时间,而不是file_get_contents函数读取URL的超时时间。
从警告信息来看,是被抓取的网页出现了服务器500错误,可能是他的程序出现超时了。

如果想改变file_get_contents的超时时间,可以用resource $context的timeout参数:
$opts = array(
'http'=>array(
'method'=>"GET",
'timeout'=>60,
)
);

$context = stream_context_create($opts);

$html =file_get_contents('', false, $context);
fpassthru($fp);