php 缓存技术

<?php
$ct = 3600;                                     ////////设置缓存时间
$currpage = isset($_GET['p']) ? $_GET['p'] : 1;
$cf = "cache/pok$currpage.html";
$iscache = false;                               ////////设置缓存是否开启的条件
if($iscache && file_exists($cf) && (time()-filemtime($cf)<=$ct)){  //////////判断是否满足缓存开始的条件
    include $cf;                                                    /////// 满足条件 查看cache下面的html静态页面
}else{                                                              //      如果不满足 则执行php文件
    ob_start();                                                     //////开启 缓存
    require 'common/conn.php';
    require 'common/util.php';
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
div.pager { width: 660px; height: 50px; margin: 0 auto; padding-left: 300px; }
div.pager a { color:#000000; font-family: 宋体; font-size: 12px; border: 1px solid #Dedcdc; padding: 1px 6px; line-height: 25px; display: block; float: left; margin-right: 5px; text-decoration: none; }
div.pager a:hover { border:1px solid #bcbcbc;color: green; font-size: 12px; }
div.pager span.curr { display: block; font-size: 12px; padding: 1px 6px; line-height: 27px; display: block; float: left; margin-right: 5px; font-weight: 800; }
div.pager span.spans { display: block; color: gray; font-size: 10px; line-height: 25px; padding-top: 5px; margin-right: 6px; display: block; float: left; }
</style>
</head>
<body>
<?php
$currpage = isset($_GET['p']) ? $_GET['p'] : 1;
$r = pager($m,'st2',$currpage,15,'sname,sage');
while($row = $r[0]->fetch_row()){
    printf("姓名:%s,年龄:%d<br/>",$row[0],$row[1]);  
}
echo $r[4];
$m->close();
?>
</body>
</html>
<?php
    $html = ob_get_contents();                                      /////////缓存关闭
    file_put_contents($cf,$html);                                   /////////输出缓存文件到cache目录中
}
?>


你可能感兴趣的:(缓存,技术php)