I have pulled 7 RSS feed and parse in our website. But the parse time is very slow, what is the best way to parse RSS feed in PHP.
Also is there a way to GZip for faster parse time?
I use this GZip in my .htaccess file but no difference
Here’s the GZip script in my .htaccess file
# 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
Here’s my PHP code to parse RSS feeds
<?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>';
}
}
?>
any help/suggestion will be appreciated.
It seems you are parsing your feeds online, on each and every user request.
It always would be slow. It is network, you know.
The only sensible way of reading RSS feeds is asynchronous one. One script to parse them regularily and update the local database and another to show entries from the local database.
And, you know, gzipping output has very little to do with parsing inbound data. Go figure.