我在循环中使用file_get_contents()
方法调用一系列链接。每个链接的处理时间可能超过15分钟。现在,我担心PHP的file_get_contents()
是否有超时时间?
如果是,它将通过调用超时,并移动到下一链接。我不想在前一个链接没有完成的情况下调用下一个链接。
所以,请告诉我file_get_contents()
是否有超时时间。将包含file_get_contents()
的文件设置为set_time_limit()
为零(无限制)。
发布于 2012-04-20 04:46:37
默认超时由default_socket_timeout
ini-setting定义,即60秒。您还可以动态更改它:
ini_set('default_socket_timeout', 900); // 900 Seconds = 15 Minutes
设置超时的另一种方法是使用stream_context_create
将超时设置为正在使用的HTTP stream wrapper的HTTP context options:
$ctx = stream_context_create(array('http'=>
array(
'timeout' => 1200, //1200 Seconds is 20 Minutes
)
));
echo file_get_contents('http://example.com/', false, $ctx);
发布于 2016-07-29 01:13:58
当我在我的主机中更改php.ini时,对于我的工作:
; Default timeout for socket based streams (seconds)
default_socket_timeout = 300
https://stackoverflow.com/questions/10236166
复制相似问题