製做smarty模版緩存文件

<?php
$p = 1;
if(!empty($_GET["page"]))
{
$p = $_GET["page"];
}php

$filename = "../cache/huancun{$p}.html"; //緩存文件存放的位置html

$time = 30; //緩存有效期10秒sql


/*var_dump((filemtime($filename)+$time)<= time());
echo filemtime($filename)+$time;
echo time();*/緩存

//判斷緩存文件是否存在,若是緩存文件存在直接調用緩存,若是緩存文件不存在從新緩存
if(file_exists($filename) && ((filemtime($filename)+$time)>= time()) )
{
//直接調用緩存
include($filename);
}
else
{
//從新緩存
ob_start(); //開啓內存緩存

include("../init.inc.php");
include("../DBDA.php");
$db = new DBDA();
$sall = "select count(*) from nation";
$zts = $db->StrQuery($sall);
include("../page.class.php");
$page = new Page($zts,5);

$sql = "select * from nation ".$page->limit;
$arr = $db->Query($sql);

$smarty->assign("fpage",$page->fpage());
$smarty->assign("shuzu",$arr);
$smarty->display("huancun.html");

$str = ob_get_contents(); //獲取內存中的緩存內容
file_put_contents($filename,$str);

ob_flush(); //關閉內存緩存

echo "#######################################";
}htm

相關文章
相關標籤/搜索