<?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目錄中}?>
本文出自 “mysql_php_apache” 部落格,請務必保留此出處http://johnzxw.blog.51cto.com/4510670/1299932