<?php //引入配置文件 $fillname="../cache/testhuancun.html"; //设置一个缓存时间 $time=5; //判断如果缓存文件不存在的话 if(!file_exists($fillname) || filemtime($fillname)+$time<time()) { //开启缓存 ob_start(); include("../init.inc.php"); include("../DBDA.class.php"); $db=new DBDA(); $sql="select * from nation"; $attr=$db->Query($sql); $smarty->assign("nation",$attr); $smarty->display("test.html"); //把内存里面的内容读出来 $nr=ob_get_contents(); //将读到的内容存放到缓存文件 file_put_contents($fillname,$nr); //清除缓存 ob_flush(); echo "##########################"; } //如果缓存文件存在的话 else { include($fillname); }