file_get_contents() 中的超時設定
在循環中使用file_get_contents() 從多個連結檢索內容時,考慮潛在的連結可能性至關重要超時。
File_get_contents()逾時時間:
是的,file_get_contents() 確實有一個由default_socket_timeout ini 設定定義的預設逾時時間,該時間設定為60 秒( 1 分鐘)。這意味著,如果與遠端資源建立連線的時間超過 60 秒,file_get_contents() 將會逾時。
自訂逾時:
覆寫預設值逾時,您可以使用下列方法:
ini_set('default_socket_timeout', 900); // 900 Seconds = 15 Minutes
$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()”中配置循環連結逾時?的詳細內容。更多資訊請關注PHP中文網其他相關文章!