<?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目錄中 } ?>