页面静态化,顾名思义是将动态的服务器端编程语言(专业超文本预处理器的缩写)转化为静态的Html,流程如下图
用户访问index.php,如果存在index.html且在有效期内,则直接输出index.html,否则去生成index.html
文件_放_内容()输出静态文件
ob_start()开启服务器端编程语言(专业超文本预处理器的缩写)缓冲区
ob_get_contents()获取缓冲区内容
ob_clean()清空缓冲区
ob_get_clean()相当于ob_get_contents() ob_clean()
代码示例
?phpif (file_exists(' ./html/index。html ')time()-file ctime(' ./html/index。html ')30){ require _ once ' ./html/index。html ';} else { //引入数据库配置要求一次./config/数据库。PHP ';//引入Medoo类库要求一次./libs/medoo。PHP ';//实例化对象$ db=new me doo($ config);//获取数据$users=$db-select('user ',['uid ',' username ',' email ']);//引入模板要求一次./模板/索引。PHP ';//写入超文本标记语言文件_put_contents(' ./html/index.html ',ob _ get _ contents());}