php - 静态页面怎么实现,就是把数据写入到html页面在缓存起来?
阿神
阿神 2017-04-11 09:41:59
[PHP讨论组]

static.php 文件

$file  = "static.html";
$ctime =filectime($file);
$expr = 3600*24*10;//静态文件有效期,十天
if(file_exists($file)) {
    if($ctime+$expr> time()){
        echo file_get_contents($file);
    }else{
        unlink($file);//删除过期的静态页文件
         ob_start();
         //从数据库取出数据写入 static.html 
         
        $content = ob_get_contents();
        file_put_contents($file,$content);//写入内容到对应静态文件中
        ob_end_flush();
    }
    
 }else{
           ob_start();
         //从数据库取出数据写入 static.html 
        
        $content = ob_get_contents();
        file_put_contents($file,$content);//写入内容到对应静态文件中
        ob_end_flush();
    
 }

?>

static.html 页面

  
静态页面