file_get_contents()是否具有超时设置? [英] Does file_get_contents() have a timeout setting?
问题描述
我正在循环中使用 file_get_contents()
方法调用一系列链接.每个链接可能需要15分钟以上的时间来处理.现在,我担心PHP的file_get_contents()
是否有超时期限?
I am calling a series of links using the file_get_contents()
method in a loop. Each link may take more than 15 minutes to process. Now, I worry about whether PHP's file_get_contents()
has a timeout period?
如果是,它将因通话超时而移至下一个链接.我不想在未完成前一个链接的情况下调用下一个链接.
If yes, it will time out with a call and move to next link. I don't want to call the next link without the prior one finishing.
所以,请告诉我file_get_contents()
是否有超时期限.包含file_get_contents()
的文件被设置为 set_time_limit()
为零(无限制).
So, please tell me whether file_get_contents()
has a timeout period. The file which contains the file_get_contents()
is set to set_time_limit()
to zero (unlimited).
推荐答案
默认超时由 default_socket_timeout
初始设置,即60秒.您也可以随时更改它:
The default timeout is defined by default_socket_timeout
ini-setting, which is 60 seconds. You can also change it on the fly:
ini_set('default_socket_timeout', 900); // 900 Seconds = 15 Minutes
设置超时的另一种方法是使用 stream_context_create
进行设置超时为
Another way to set a timeout, would be to use stream_context_create
to set the timeout as HTTP context options of the HTTP stream wrapper in use:
$ctx = stream_context_create(array('http'=>
array(
'timeout' => 1200, //1200 Seconds is 20 Minutes
)
));
echo file_get_contents('http://example.com/', false, $ctx);
这篇关于file_get_contents()是否具有超时设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!