您好,欢迎访问一九零五行业门户网

php真静态缓存 ob系统函数 php 函数返回值 php 数组 php date函

真静态缓存:(真的生成一个html页面,在接下来的操作中直接调用该html)
第一次(刷新网页面)判断是否存在缓存文件 (可设置一时间)
如果不存在 第一次是(可根据pdo)连接数据库 查找数据 输出到页面 并且同时缓存(写入)到本地一个.html文件;
再次(刷新网页面) 判断是否存有该缓存文件时
当存在缓存文件,直接查找本地缓存(file_get_content) 读取出来
以下代码在ci框架中编写完成
$time = 10; //设置缓存页面过期时间if(!is_file(obtest.html) || time()-filemtime(obtest.html)>$time){ob_start(); //打开缓冲区 $arr['res']=$this->db->get('user')->result_array();$this->load->view('welcome_message',$arr);//print_r($arr);$info = ob_get_contents(); //得到缓冲区的内容并且赋值给$info $file = fopen('obtest.html', 'w'); //打开文件info.txt fwrite($file, $info); //写入信息到info.txt fclose($file); //关闭文件info.txt}else{ echo cache:; echo file_get_contents(obtest.html);}
fopen 和 filemtime 方法的使用:
fopen() 函数打开文件或者 url。fopen(文件名称,文件访问类型)w写入方式打开。filemtime() 函数返回文件内容上次的修改时间,里面跟文件名。
').addclass('pre-numbering').hide(); $(this).addclass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadein(1700); }); }); 以上就介绍了php真静态缓存 ob系统函数,包括了php,函数方面的内容,希望对php教程有兴趣的朋友有所帮助。
其它类似信息

推荐信息