控制Lilina中缓存文件是否过时的机制

    这个问题的关键是在PHP取得文件的最后修改时间, 其实很简单:

function mtime($filename)
{
        $fd = fopen($filename, "r");
        $fstat = fstat($fd);
        fclose($fd);
        return $fstat['mtime'];
}

    取得当前时间, 返回自从Unix纪元(格林威治时间1970年1月1日 00:00:00)到当前时间的秒数:

  $curtime = time();
  echo "Current Date:".date('Y-m-d', $curtime)."\n";

    两个时间相减得到的结果是秒数. 可以用如下方法确定缓存文件是否过时:

if ( (time() - mtime($filename)) > $CACHE_FILE_TIMEOUT) then
{
  ...
}

    以上是我在改动Lilina的缓存机制时学到的.

发表留言:

« Previous | Main | Next »

英语900句 | English 900

  • My grandma is 40 years older than me.
  • 我祖母比我大40岁.
  • This river is one third as long as that river.
  • 这条河只有那条河的三分之一长.
  • What's the shape of your balloon?
  • 你的气球是什么形状?
  • How wide is this bridge?
  • 这座桥有多宽?
  • How thick is the ice here?
  • 这儿的冰有多厚?