我有这个脚本,它输出一个 rss 提要。我想做的是让它尝试到达 rss url 5 秒之类的顶部,如果它不能,那么我希望它加载服务器上的备份 xml 文档。这就是我所拥有的,但它不起作用:
<?php
include '../php/connect.php';
$metaData = mysql_query("SELECT * FROM `siteinfo`") or die("couln't find table :(");
$displayData = mysql_fetch_assoc($metaData);
$url = $displayData['status'];
$xml = file_get_contents($url);
stream_set_timeout($xml, 5);
if ($xml == FALSE) {
$xml = simplexml_load_file('backUpXml.xml');
foreach ($xml->channel->item as $item) {
echo '<a href="'.$item->guid.'" alt="'.$item->title.'" target="_blank">', substr($item->title, 0, 62), '...</a><br /><span>', substr($item->pubDate, 4, 18),'</span><br /><hr /><br />';
}
} else {
$xml = simplexml_load_file($url);
foreach ($xml->channel->item as $item) {
echo '<a href="'.$item->guid.'" alt="'.$item->title.'" target="_blank">', substr($item->title, 0, 62), '...</a><br /><span>', substr($item->pubDate, 4, 18),'</span><br /><hr /><br />';
}
}
?>
我收到超时错误,仅此而已。任何见解都会很棒!