TokTak Tw
TokTak Tw

Reputation: 21

How to limit the timeout when running DOMDocument->loadHtmlFile?

I'm trying to get the content from some website but if the website is down, it takes a really long time to open (like 1 min).

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

How can I make it timeout after 5 seconds?

Upvotes: 2

Views: 819

Answers (1)

Rab
Rab

Reputation: 35572

You can use CURL to time the code and to timeout if the remote call takes too long

the following id the link where you can some code too

Link to curl code

Upvotes: 2

Related Questions