我正在阅读 rss 提要并检查我想知道它需要多少时间来调用
$homepage = file_get_contents('http://www.forbes.com/news/index.xml');
为此我正在使用
<?php
$start = microtime(true);
$homepage = file_get_contents('http://www.fohgggrbes.com/news/index.xml');
$end = microtime(true);
$dur=$end-$start;
echo $dur;
$xml = simplexml_load_string($homepage,'SimpleXMLElement', LIBXML_NOCDATA);
echo '<pre>';
?>
但我的要求是首先我检查文件是有效的 xml,如果是,那么它的显示响应时间
$homepage = file_get_contents('http://www.forbes.com/news/index.xml');
或者如果 XML 文件无效,则显示错误消息。我想使用 try 和 catch 异常。