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

<?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
}
?>
原文地址:https://www.cnblogs.com/yszr/p/9912086.html