2013-05-17 34 views
2

我試圖從某個網站獲取內容,但如果網站已關閉,需要很長時間才能打開(如1分鐘)。如何限制運行DOMDocument-> loadHtmlFile時的超時時間?

$html = new DOMDocument(); 
@$html->loadHtmlFile('http://somewebsite.com'); 
$xpath = new DOMXPath($html); 
$links = $xpath->query("//p[@class='result']"); 

如何在5秒後使其超時?

+0

你基本上要檢查鏈接如果一個網站在線...檢查這一個:http://css-tricks.com/snippets/php/check-if-website-is-available/ – bestprogrammerintheworld

+0

哇這真的幫助^^謝謝bestprogrammerintheworld –

+0

你'歡迎光臨:-) – bestprogrammerintheworld

回答

2

您可以使用CURL時間代碼和超時如果遠程通話時間過長

以下ID,您可以在一些代碼太多

Link to curl code