码迷,mamicode.com
首页 > Web开发 > 详细

接上篇,php生成静态页面,加上页面时间缓存

时间:2018-11-05 22:52:40      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:info   html   state   where   time   success   and   保存   缓存   

<?php require_once(dirname(__FILE__).‘/include/config.inc.php‘); ?>
 <?php
    $dosql->Execute("SELECT * FROM `#@__infolist` WHERE delstate=‘‘ AND checkinfo=true ORDER BY orderid DESC LIMIT 0,5");
//静态页面加缓存时间,如果页面已经存在或者没有超出时间,则默认加载静态页面,否则,生成静态页面:filemtime读取文件修改时间
if(is_file(‘./index.html‘) && (time() - filemtime(‘./index.html‘)) < 300) {//echo 88;die;
  require_once(‘./index.html‘);
}else {//echo 2222;die;
//start

    ob_start();//开启缓存 
    echo ‘<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />‘;
    while($row = $dosql->GetArray())
    {
?>
  
    <p><?php echo $row[‘title‘];?> +</p>
<?php
}

  if(file_put_contents( ‘index.html‘, ob_get_contents() )){

    echo ‘success‘;
  }else{
    echo ‘error‘;
  };//把生成的静态内容保存到index.html文件,而不是输出到浏览器

//end
}
?>

 

接上篇,php生成静态页面,加上页面时间缓存

标签:info   html   state   where   time   success   and   保存   缓存   

原文地址:https://www.cnblogs.com/yszr/p/9912086.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!