I'm using a library called Simple HTML DOM
One of it's methods, loads the url into a DOM object:
function load_file()
{
$args = func_get_args();
$this->load(call_user_func_array('file_get_contents', $args), true);
// Throw an error if we can't properly load the dom.
if (($error=error_get_last())!==null) {
$this->clear();
return false;
}
}
In order to test error handling, I created this code:
include_once 'simple_html_dom.php';
function getSimpleHtmlDomLoaded($url)
{
$html = false;
$count = 0;
while ($html === false && ($count < 10)) {
$html = new simple_html_dom();
$html->load_file($url);
if ($html === false) {
echo "Error loading url!\n";
sleep(5);
$count++;
}
}
return $html;
}
$url = "inexistent.html";
getSimpleHtmlDomLoaded($url);
The idea behind this code it's to try again if the url is failing to load, if after 10 attemps still fails, it should return false.
However it seems that with an inexistent url, the load_file method never returns false.
Instead I get the following warning message:
PHP Warning: file_get_contents(inexisten.html): failed to open stream
Any idea how to fix this?
Note: Preferably I would like to avoid hacking into the library.