我在我們的網站上拉了7個RSS訂閱源並解析。但解析時間非常緩慢,在PHP中解析RSS提要的最佳方式是什麼?在PHP中解析RSS feed的最快方法是什麼?
也有一種方法來GZip更快的解析時間?
我用這個的GZip在我的.htaccess文件,但沒有任何區別
下面是我的.htaccess文件
# compress text, html, javascript, css, xml: AddOutputFilterByType
DEFLATE text/plain text/html text/xml text/css application/xml
application/xhtml+xml application/rss+xml application/javascript
application/x-javascript
這裏gzip的劇本是我的PHP代碼來解析RSS源
<?php
function getFeed($feed_url){
$content = file_get_contents($feed_url);
$x = new SimpleXMLElement($content);
for ($i=0; $i<=4; $i++){
$entry = $x->channel->item[$i];
// if promotion price is set, then use the promotion price instead of Normal Price
$normal = $entry->NormalPrice;
$promo = $entry->PromotionPrice;
// Get the links and titles
$image = $entry->Image->Url;
$link = $entry->link;
$title = $entry->title;
if((isset($promo)) && ($promo > 0)){
$price = 'R '.number_format(trim($promo), 2);
}else if($normal > 0 && $promo == 0){
$price = 'R '.number_format(trim($normal), 2);
}else if((empty($normal) && empty($promo)) || (($normal == 0) && ($promo == 0))){
$price = 'Out Of Stock';
}
echo '<div class="rssImages">';
echo '<div class="imageCover">';
echo '<a href="'.$link.'"><img src="'.$image.'" /></a><br /><br />';
echo '</div>';
echo '<div class="rssCntImg">';
echo '<a href="'.$link.'" id="rsslinks">'.$title.'</a> <br />';
echo '</div>';
echo '<strong>'.$price."</strong>";
echo '<label class="cleared"></label>';
echo '</div>';
}
}
?>
任何幫助/建議將不勝感激。
定義「非常慢」 –
這只是「慢」爲服務於飼料... – Alex
你有定時的不同步驟,發現您的瓶頸服務器? Apache中的GZip必須使用輸出編碼,從服務器到訪問者。使用GZip下載外部供稿將節省帶寬(和下載速度),但會增加處理器負荷併爲解開響應增加額外時間。 –