页面静态化思路
2013-06-09 10:09
134 查看
<?php
$_time =5;//缓存有效时间
$dir="";//当前目录下生成缓存文件,便于测试
function cache_start($_time, $dir)
{
$cachefile = $dir.sha1($_SERVER['REQUEST_URI']).'.html';
$cachetime = $_time;
ob_start();
/*-------------------------
**判断:1.缓存文件存在并且
** 2.未过期
--------------------------*/
if(file_exists($cachefile) && (time( )-$cachetime < filemtime($cachefile)))
{
include($cachefile);
ob_end_flush();
exit;
}
}
function cache_end($dir)
{
$cachefile = $dir.sha1($_SERVER['REQUEST_URI']).'.html';
$fp = fopen($cachefile, 'w');
fwrite($fp, ob_get_contents());
fclose($fp);
ob_end_flush();
}
cache_start($_time, $dir);
//以下是输出的内容,放在cache_start和cache_end两个方法之间
for($i=0;$i<=100;$i++)
{
for($j=0;$j<=$i;$j++)echo $j."-";
echo "<br>";
}
cache_end($dir);
$_time =5;//缓存有效时间
$dir="";//当前目录下生成缓存文件,便于测试
function cache_start($_time, $dir)
{
$cachefile = $dir.sha1($_SERVER['REQUEST_URI']).'.html';
$cachetime = $_time;
ob_start();
/*-------------------------
**判断:1.缓存文件存在并且
** 2.未过期
--------------------------*/
if(file_exists($cachefile) && (time( )-$cachetime < filemtime($cachefile)))
{
include($cachefile);
ob_end_flush();
exit;
}
}
function cache_end($dir)
{
$cachefile = $dir.sha1($_SERVER['REQUEST_URI']).'.html';
$fp = fopen($cachefile, 'w');
fwrite($fp, ob_get_contents());
fclose($fp);
ob_end_flush();
}
cache_start($_time, $dir);
//以下是输出的内容,放在cache_start和cache_end两个方法之间
for($i=0;$i<=100;$i++)
{
for($j=0;$j<=$i;$j++)echo $j."-";
echo "<br>";
}
cache_end($dir);
相关文章推荐
- 关于分页时静态化页面的一点思路
- ASP.NET MVC 页面静态化操作的思路
- asp.net页面静态化实现思路
- php页面静态化实现思路
- 页面静态化的思路
- PHP学习笔记(6) PHP静态化页面的实现思路
- php页面静态化实现思路
- 如何做URL静态化 和页面的静态化
- 页面静态化工具类
- PHP 页面静态化/纯静态化/伪静态化
- PHP实现伪静态化页面的具体实现方式
- j2ee页面静态化方案encache web cache框架详解1
- IIS不用rewrite实现页面静态化的方法
- 博客系统-静态化页面
- 响应式页面设计思路
- php实现页面静态化(纯静态&&伪静态)
- 【学习笔记】PHP实现页面静态化
- 通过Freemarker实现页面静态化的基本操作
- 利用ResultFilter实现asp.net mvc3 页面静态化
- 页面静态化(JSP动态页面转静态化)