Does File_Get_Contents() Timeout?
File_get_contents() is a powerful tool for retrieving content from remote URLs. However, concerns arise regarding potential timeouts when dealing with lengthy processes.
Does File_Get_Contents() Have a Timeout?
Fortunately, file_get_contents() does have a timeout mechanism. By default, the timeout is set by the default_socket_timeout ini-setting, which is configured to 60 seconds. This means that if the content cannot be retrieved within 60 seconds, a timeout exception will be thrown.
Customizing the Timeout
The default timeout can be customized to suit specific needs. Two methods can be used:
ini_set('default_socket_timeout', 900); // 900 Seconds (15 Minutes)
$ctx = stream_context_create(array( 'http' => array( 'timeout' => 1200 // 1200 Seconds (20 Minutes) ) )); echo file_get_contents('http://example.com/', false, $ctx);
By setting a higher timeout, users can ensure that file_get_contents() waits longer before triggering a timeout.
以上是`file_get_contents()` 有逾時機制嗎?的詳細內容。更多資訊請關注PHP中文網其他相關文章!