RSS generator with caching function

牧云@^-^@ 提交于 2019-12-11 06:43:36

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/3538000/rss-generator-with-caching-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!