首页 > php技术/ 正文
给大家一段php文件缓存技术实现代码!下面是一个php教程缓存文件实现类,根据我的经验,缓存文件是根据用户设置的时间与文件生成的日间以及当前时间进行比较,然后再判断是否需要重新生成缓存文件。*/
class pagecache {
/**
* @var string $file 缓存文件地址
* @access public
*/
public $file;
/**
* @var int $cachetime 缓存时间
* @access public
*/
public $cachetime = 3600;
/**
* 构造函数
* @param string $file 缓存文件地址
* @param int $cachetime 缓存时间
*/
function __construct($file, $cachetime = 3600) {
$this->file = $file;
$this->cachetime = $cachetime;
}
/**
* 取缓存内容
* @param bool 是否直接输出,true直接转到缓存页,false返回缓存内容
* @return mixed
*/
public function get($output = true) {
if (is_file($this->file) && (time()-filemtime($this->file))<=$this->cachetime && !$_get['nocache']) {
if ($output) {
header('location:' . $this->file);
exit;
} else {
return file_get_contents($this->file);
}
} else {
return false;
}
}
/**
* 设置缓存内容
* @param $content 内容html字符串
*/
public function set($content) {
$fp = fopen($this->file, 'w');
fwrite($fp, $content);
fclose($fp);
}
}
更多android培训课程,php培训学校,android 软件,郑州android技术,jave课程,河南java相关文章
- php代码很重要,但不是最重要的!
- 郑州php培训哪里最好
- 高中生能学会网络技术吗
- PHP二次开发培训哪个培训机构好?
- 郑州有好点的mysql开发培训学校吗
- Php优化的小技巧
- 郑州学习php开发到哪里培训
- 如何学好PHP技术
- php大学生培训怎么样
- mysql数据库培训的内容
- 做一个php程序员容易吗?
- PHP开发培训班最好的是哪个呢?
- 学完php是不是就可以建网站了?
- 新手必看:php网站设计遇到的问题
- 郑州php培训学校哪个好?
- 怎么才能学好php技术?
- 菜鸟该怎么学习PHP技术呢?
- 怎么学好数据库呢?
- 数据库开发需要学好什么基础知识呢
- 数据库工程师培训学校哪里有啊?
- 我在学数据库,谁知道好一点的sql server学校?
- 哪里可以学到数据库实用技术?
- 怎样学习access数据库呢?
- PHP技术之EVAL的利用防范
- PHP和Java哪个更有前途一些
- 郑州php培训学校培训的快就业好的学校
- 网络安全之PHP安全编程建议
- PHP怎么样看看大家怎么说的
- 搜索
-
- 热门标签