Failsafe for PHP Simple HTML DOM Parser
Using PHP Simple HTML DOM Parser (http://simplehtmldom.sourceforge.net), I
recently had a situation where the external webpage I routinely fetch was
not responding (their servers were down). Because of this the my own
website would not load (instead it showed errors after a lengthy wait
period).
What would be the best way to add a failsafe to this parser upon an
unsucessful fetch attempt?
I have tried to use the following below without success.
include('./inc/simple_html_dom.php');
$html = file_get_html('http://client0.example.com/dcnum.php?count=1');
$str = $html->find('body',0);
$num = $str->innertext;
if(!$html)
{
error('No response.')
}
$html->clear();
unset($html);
EDIT: I haven't had time to try this yet, but perhaps I could place my
'if' statement directly after the first line (before the
$html->find('body',0) part).
No comments:
Post a Comment