具有缓存功能的RSS生成器
您是否偶然知道任何具有缓存功能的优秀rss生成器脚本.到目前为止,我在网上找到的所有脚本都不支持缓存!我需要在指定的时间段内从数据库自动生成rss的内容.
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.
预先感谢
首先,要将缓存添加到脚本 ,似乎并不难将 Zend_Feed
和
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');
当然,最佳方法可能只是使用当前的提要生成器并将输出保存到文件中.使用该文件作为RSS feed,然后使用cron/web hooks/queue/whatever生成静态文件.与让生成脚本进行缓存相比,这将更简单并且使用更少的资源.
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);
现在,提要链接为/feed.rss
,只要需要刷新feedGen.php
,就可以运行它.提供静态文件(甚至没有被php解析)意味着服务器要做的事更少.
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.