具有缓存功能的RSS生成器 [英] RSS generator with caching function

查看:122
本文介绍了具有缓存功能的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

我不知道您如何形成RSS,但是您可以

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.

这篇关于具有缓存功能的RSS生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆