我正在使用 file_get_contents()
调用一系列链接循环中的方法。每个链接的处理时间可能超过 15 分钟。现在,我担心PHP的file_get_contents()
是否有超时时间?
如果是,它将超时并移至下一个链接。我不想在没有完成前一个链接的情况下调用下一个链接。
那么,请告诉我 file_get_contents()
是否有超时时间。包含 file_get_contents()
的文件设置为 set_time_limit()
归零(无限)。
最佳答案
默认超时由 default_socket_timeout
ini-setting 定义,即 60 秒。您也可以随时更改它:
ini_set('default_socket_timeout', 900); // 900 Seconds = 15 Minutes
另一种设置超时的方法是使用 stream_context_create
将超时设置为 HTTP context options的HTTP stream wrapper使用中:
$ctx = stream_context_create(array('http'=>
array(
'timeout' => 1200, //1200 Seconds is 20 Minutes
)
));
echo file_get_contents('http://example.com/', false, $ctx);
关于php - file_get_contents() 是否有超时设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10236166/