tags:

views:

28

answers:

1

Do you happen to know any good rss generator script with caching function. All the script I have found over the net so far doesn't support caching! I need the the content of rss to be generated automatically from database in a specified period of time.

Thanks in advance

+3  A: 

First, to add caching to the script, it seems like it wouldn't be too hard to put Zend_Feed and Zend_Cache together - or just wrap your current generation script with Zend_Cache.

Just setup the cache with your lifetime:

$frontendOptions = array(
  'lifetime' => 7200, // cache lifetime of 2 hours
  'automatic_serialization' => true
);

Then check if the cache is still valid:

if(!$feed = $cache->load('myfeed')) {
  //generate feed
  $cache->save($feed, 'myfeed');
}

//output $feed

I don't know how you form your RSS, but you can import an array structure to Zend_Feed:

$rssFeedFromArray = Zend_Feed::importArray($array, 'rss');

Of course the best way may be to just use your current feed generator and save the output to a file. Use that file as the RSS feed, then use cron/web hooks/queue/whatever to generate the static file. That would be simpler, and use less resources, than having the generation script do the caching.

//feedGen.php
//may require some output buffering if the feed generator outputs directly
$output = $myFeedGenerator->output();
file_put_contents('feed.rss', $output);

Now the feed link is /feed.rss, and you just run feedGen.php whenever it needs to be refreshed. Serving the static file (not even parsed by php) means less for your server to do.

Tim Lytle