php实现页面静态化
2017-09-08 16:12
387 查看
PHP文件执行顺序
语法解析 => 编译 => 运行动态程序
1,连接数据库服务器或者缓存服务器。2,获取数据
3,填充到模版
4,呈现给用户
配置项
output_buffering : 开启缓存函数
ob_start() : 打开输出缓存ob_get_contents() : 返回输出缓存区的内容
ob_get_clean():得到当前缓存区的内容并删除当前输出缓存。 ob_clean():清空输出缓存区。
file_put_contents():将一个字符串写入文件。
filemtime():取得文件修改时间。
生成静态页面
页面添加缓存时间if(is_file(‘./index.html’) && time()-filetime(‘./index.html’) < 300){
require_once(‘./index.html’);
}else{
require_once(‘./db.php’);
conn=mysqlconnect(‘localhost′,′root′,′aa′);sql = “select * from tableA”;
result=mysqlquery(sql,conn);news = array();
while(row=mysqlfetcharray(result)){
news[]=row;
}
ob_start();
//引入模版文件
require_once(‘./template/smarty.php’);
file_put_contents(‘index.html’,ob_get_contents());
}
开始处理伪静态文件的请求
if(preg_match(‘/^\/(\d+)\/(\d+).html/’),$_SERVER[‘PATH_INFO’],$arr){$type = $arr[1];
$cate_id = $arr[2];
}else{
//TODO
}
nginx下reqrite配置
server{listen 80;
server_name sina.com;
index index.php index.html;
root /root/static;
location /{
if(!-e $request_filename){
rewrite ^/detail/([0-9]*).html\$/ /detail.php?id=\$1 last;
break;
}
}
}
相关文章推荐
- 单例模式的数据库连接和PHP实现页面静态化的第一种方法
- PHP 实现页面静态化的几种方法
- php页面静态化实现思路
- PHP实现伪静态化页面的具体实现方式
- PHP实现页面静态化的超简单方法
- 【学习笔记】PHP实现页面静态化
- PHP实现页面静态化——全部纯静态化
- PHP实现页面静态化
- PHP实现HTML页面静态化的方法
- PHP页面静态化实现
- 三,PHP缓存机制实现页面静态化
- php实现页面静态化
- PHP实现HTML页面静态化的方法
- php动态网页实现页面静态化 通过在初次被访问时生成html文件保存起来,下次该PHP程序被访问时就直接找到以前被访问过的html页面
- 使用php实现伪静态化页面
- (PHP学习笔记)实现页面静态化
- php实现页面静态化(纯静态&&伪静态)
- PHP实现页面静态化——全部纯静态化
- PHP实现页面静态化的超简单方法
- PHP实现页面静态化——局部动态化