« 为lilina增加文本预缓存支持(html cache) | Main | 个性化GMail, hotmail, Yahoo!邮箱图标 »

版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明。
本文网址:http://www.hzqbbc.com/blog/arch/2005/05/lilina_eceaelil.html
 

May 15, 2005

发布lilina 预缓存补丁(lilina cache patch)

前几天对lilina的提速修改,经过整理后,做了一个补丁。经过约一周时间的测试,感觉稳定性和可靠性方面已没什么问题。由于浏览器访问的是html文件,所以速度相当满意。为了使cache文件能自动更新,我使用了一个小技巧:用<frame> 嵌套了index.php,这样每次访问cache文件时,都会调用index.php,index.php会判断cache文件是否过期,过期了则后台重建;如无过期则显示cache文件的创建时间,这样非常方便。

下图是更新cache时显示的信息,注意看红圈内的信息:
更新cache时的信息

这是使用cache时显示的信息:
使用cache时的信息

对于没有Unix环境的朋友,可以下载打了补丁后的lilina-0.7

补丁后的lilina-0.7下载

下载地址: lilina-0.7-patched.tar.gz

安装与标准的lilina没有什么区别,可以参考:小试RSS聚合器lilina,附安装方法,唯一要配置的就是$index_file及其对应的文件属性。详细见下文。

补丁的全部内容入如下:


--- index.php.old	2005-05-15 22:43:16.000000000 +0800
+++ index.php	2005-05-16 13:37:59.000000000 +0800
@@ -1,4 +1,10 @@
 <?
+/* output buffer control start */
+ob_start("callback");
+$index_file = "cache.html";
+$mt = mtime();
+$rebuild = 0;
+
 header("Content-Type: text/html; charset=utf-8");
 require_once './lib.php' ;
 
@@ -7,6 +13,39 @@
 	define('MAGPIE_CACHE_AGE',1) ;
 } 
 
+/* rebuild cache or not? */
+if(time()-$mt>MAGPIE_CACHE_AGE) {
 +	$rebuild = 1;
 +}else {
 +	return 0;
 +}
+
+/* Function used to do cache */
+function mtime() {
 +	global $index_file;
 +	$fd = fopen($index_file, "r");
 +	$fstat = fstat($fd);
 +	fclose($fd);
 +	return $fstat['mtime'];
 +}
+
+function callback($str) {
 +	global $rebuild, $index_file, $mt;
 +	$color = '#000000';
 +	$res = "<style><!-- body { font-size: 10px; font-family: Verdana; } --></style>";
 +	if($rebuild) {
  +		$color = '#ff0000';
  +		$fd = fopen($index_file, "w");
  +		fputs($fd, $str, strlen($str));
  +		fclose($fd);
  +		$time = strftime("%a %b %d %H:%M:%S, %Y", time());
  +		return $res."<b><font color=$color>Built index: $time</font></b>";
  +	}else {
  +		$time = strftime("%a %b %d %H:%M:%S, %Y", $mt);
  +		return $res."<b><font color=$color>Cache index: $time</font></b>";
  +	}
 +}
+
 /* Function used to sort rss items in chronological order */
 function date_cmp($a, $b) {
     if ($a['date_timestamp'] == $b['date_timestamp'] ) {
  @@ -166,5 +205,15 @@
     <div id="footer">powered by <a href="http://lilina.sourceforge.net/"><img src="i/logo.gif" alt="lilina news aggregator" title="lilina news aggregator" /></a> v
       <?= $LILINAVERSION ?>
     </div>
  +
  +  <div id="updater" style="display: block; position: absolute; top: 10px; right: 100px;">
  +  <iframe marginheight=0 frameborder=0 scrolling=no height=20 src="index.php"></iframe>
  +  </div>
  +
   </body>
   </html>
  +
  +<?php
  +/* flush output buffer */
  +ob_end_flush();
  +?>

将上述这段代码复制,保存到本地文件,例如lilina-cache.patch。并将patch文件上载到lilina的目录里,执行如下命令:

patch -p0 < lilina-cache.patch
这样就完成了补丁的操作。不过需要注意几点:
  • lilina-cache.patch必须放在与index.php同级目录里补丁操作方可成功
  • 默认cache文件名为cache.html,修改index.php里的$index_file变量为需要的cache文件名。
  • 注意$index_file所指向的文件/目录对于web服务器必须是可写的,建议属性改为777

    例如目前HZQBBC首页的lilina页面就是由/lilina/index.php生成的。其中$index_file = "../index.html"。除此参数及文件属性要注意外,不需要修改任何配置。

    补丁程序也可在这里下载

  • Posted by hzqbbc at May 15, 2005 03:41 PM

    Comments

    这个patch在windows下没法使用吧,使用windows平台的用户如何解决呢?

    Posted by: 勇敢的心 at May 17, 2005 08:14 AM

    我稍后将在本页提供打了补丁的lilina-0.7软件包下载,这样win32用户也可以方便的使用了。

    Posted by: hzqbbc at May 17, 2005 11:45 PM

    Warning: fopen(index.html) [function.fopen]: failed to open stream: No such file or directory in E:\www.sss.net\lilina\index.php on line 26

    Warning: fstat(): supplied argument is not a valid stream resource in E:\www.sss.net\lilina\index.php on line 27

    Warning: fclose(): supplied argument is not a valid stream resource in E:\www.sss.net\lilina\index.php on line 28


    不懂php,多出了这么几行。

    Posted by: 勇敢的心 at May 19, 2005 10:02 AM

    楼上的,假设你的网站根目录是e:\www.sss.net\ 而你的lilina放在e:\www.sss.net\lilina。

    而cache文件想放在e:\www.sss.net\cache.html的话,必须修改index.php 里的$index_file = "../cache.html";

    改完后,手工建一个cache.html,然后使其对所有人都有写的权限,这样就ok了。不过我没在windows试过,得你自己测试测试看哦。

    Posted by: hzqbbc at May 26, 2005 11:49 AM

    有问题呢~~
    index.php只有这句,什么都没有,我是用补丁后的lilina-0.7
    Cache index: Sat Jun 25 13:35:34, 2005

    Posted by: angus at June 25, 2005 01:49 PM

    楼上angus,请注意本文开头提到的嵌套index.php的技术,直接访问index.php不会有任何内容显示的。除了你提到的那行文字。

    要访问index.php文件里的$index_file变量所指定的文件,如果是linux/bsd等系统。假如lilina目录(包含index.php的)放在网站根目录下。访问的url是:
    http://xxx.abc.com/lilina/index.php

    那么$index_file 设置可以是$index_file = "../index.html";

    然后touch ../index.html 在chmod 777 ../index.html

    这样index.php在恰当的时候会更新这个index.html,第一次访问时最好强制更新,即先在浏览器访问http://xxx.abc.com/lilina/index.php?force_update=1

    然后在访问首页,效果就象我现在的网站首页一样了。速度飞快。有问题再研究。我给你发mail了。

    Posted by: hzqbbc at June 26, 2005 05:03 PM

    还是一样问题

    目录放在www/lilina 含有(index.php & index.html)

    所以这样设定
    $index_file = "./index.html";
    并且给予index.html (chmod 777)

    首先,我执行http://www.abc.com/lilina/index.php?force_update=1
    接着访问http://www.abc.com/lilina/index.php
    结果显示 Cache index: Sun Jun 26 20:18:54, 2005

    还有哪里出错???

    另外我收不到你的email?
    你有msn吗?
    my msn:sbc_penny@hotmail.com

    Posted by: angus at June 26, 2005 08:48 PM

    hi hzqbbc:

    采用lilina-0.7-patched.tar.gz下载安装完毕后
    页面仅显示
    没有内容 是我哪里出问题了
    请教 谢谢 :)

    Posted by: 若寒 at August 3, 2005 11:08 AM

    lilina.sf.net上有个好象可以分类的lilina...eee..能不能也加个缓存的patch啊.......他只提供了针对lilina的unix下的patch文件...eee....:(

    Posted by: Sidewinder at August 3, 2005 11:53 AM

    hzqbbc 你好:
    按照步骤做了一次

    页面内容显示出来
    但还是出现以下数字 自己不是很懂PHP 希望能帮忙解答下 :)


    Warning: fopen(index.html) [function.fopen]: failed to open stream: No such file or directory in E:\www.sss.net\lilina\index.php on line 26

    Warning: fstat(): supplied argument is not a valid stream resource in E:\www.sss.net\lilina\index.php on line 27

    Warning: fclose(): supplied argument is not a valid stream resource in E:\www.sss.net\lilina\index.php on line 28

    Posted by: 若寒 at August 3, 2005 11:56 AM

    楼上若寒,你的$index_file 设置是什么呢?另外,这个index_file在第一次的时候必须自己手工建立,并将属性改为777才能正常运行。

    也就是说得手工建立一个空的index.html文件放在你的E:\www.sss.net\下。且让apache能有写权限.

    Posted by: hzqbbc at August 5, 2005 04:03 PM

    hi hzqbbc:
    感谢你的补丁包 Html执行效果是很高效
    目前有一点无知,访问index.html导航栏
    24h或48h或week或all

    页面无法正常跳转,出现类似提示:
    Cache index: Tue Aug 16 12:52:48, 2005

    是哪里还需要相应的修改么
    盼回

    Posted by: 若寒 at August 16, 2005 01:07 PM

    to 若寒
    http://www.kylinx.net/lilina/cache24.html
    http://www.kylinx.net/weblog/p/lilina_cache_patch.php
    这两个应该是你想要的吧^_^

    Posted by: kaph at August 23, 2005 06:57 PM

    to若寒“24h或48h或week或all

    页面无法正常跳转,出现类似提示:”

    这个可能是你想要的

    http://www.kylinx.net/weblog/p/lilina_cache_patch.php

    http://www.kylinx.net/lilina/cache24.html

    解决了“24h或48h或week或all”的问题。

    Posted by: kaph at August 23, 2005 07:04 PM

    你好,站长

    我也安装了你提供的path版本lilina,是不是在安装你所提供的补丁版本后不用专门打补丁/?

    我始终不能让lilina自动获得页面缓存,,几乎每次都是自动更新,请问这是怎么回事/?一定要按照你所说得使用命令行打补丁? 希望能多和你交流haospoke at gmail dot com,谢谢

    Posted by: haospoke at November 17, 2005 09:21 PM

    你好hzqbbc,,我看完了上面的帖子和评论,,我也遇到了一个问题,这是我用你提供的lilina做的,http://www.haospoke.com/lilina/

    始终只出现Cache index: Thu Nov 17 11:12:07, 2005几个字,,我强制更新后会变成新的时间.

    catch.html文件我也建了,$index_file函数也修改成为 ./catch.html了,,但是为什么还是这个样子,当然cache文件的属性也是777,cache&index文件都是在lilina同一个目录中的,我看几乎完全按照你所说的安装的.请问这是怎么回事

    Posted by: haospoke at November 18, 2005 12:17 AM

    我使用这个方法修改后的lilina打包下载
    http://demo.ose.com.cn/lilina/lilina_0.7_ose.rar
    下载后修改一下conf.php,然后运行edit.php增加feed就行了。

    Posted by: firefly at January 13, 2006 05:12 PM

    终于搞定了!
    原先一直是空白一片,后来发现原来是index_file的地址有吴。原来用html代码地址在同级目录好象是不用“./”的怎么到了php就有了,搞不懂!

    Posted by: leeinsun at May 20, 2006 12:06 PM

    终于搞定了!
    原先一直是空白一片,后来发现原来是index_file的地址有误。原来用html代码地址在同级目录好象是不用“./”的怎么到了php就有了,搞不懂!

    还有一个就是怎么让24 48 168 all周期正常显示?
    看了下面的这个我还是不明白:
    “to 若寒
    http://www.kylinx.net/lilina/cache24.html
    http://www.kylinx.net/weblog/p/lilina_cache_patch.php
    这两个应该是你想要的吧^_^ ”
    而且我看他的显示跟你的不一样,你的无论如何在地址栏显示的都一样,怎么实现的,能告诉我?谢谢了!

    Posted by: leeinsun at May 20, 2006 01:17 PM

    请教一下,页面可以显示,为什么会上面多了出错的信息呢?
    http://aiyin.net/rss/c.html

    Warning: fopen(c.html) [function.fopen]: failed to open stream: No such file or directory in D:\www\aiyin\rss\index.php on line 31

    Warning: fstat(): supplied argument is not a valid stream resource in D:\www\aiyin\rss\index.php on line 32

    Warning: fclose(): supplied argument is not a valid stream resource in D:\www\aiyin\rss\index.php on line 33

    Warning: Cannot modify header information - headers already sent by (output started at D:\www\aiyin\rss\index.php:1) in D:\www\aiyin\rss\index.php on line 13

    Posted by: colordesign at June 19, 2006 01:01 PM

    Post a comment




    Remember Me?

    (you may use HTML tags for style)