Checking whether a URL is valid is a different thing than checking whether the XML is valid. When you try to load an invalid URL, the error is usually something like
failed to open stream: php_network_getaddresses: getaddrinfo failed
However, that error stems from the stream wrapper, while any XML validation is done after that by libxml. Hence, you need to check two different things. Below code will take both into account:
libxml_use_internal_errors(true);
$start = microtime(true);
$rss = @simplexml_load_file(
'http://www.fohgggrbes.com/news/index.xml',
'SimpleXMLElement',
LIBXML_NOCDATA
);
$end = microtime(true);
$errors = array_filter(
array(error_get_last(), libxml_get_errors()),
function($val) { return !empty($val); }
);
print_r(empty($errors) ? $end - $start : $errors);
libxml_use_internal_errors(false);
I leave it up to you to wrap that into a class and throw exceptions if you want to use try/catch.