最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php 缓存文件入门程序
时间:2009-11-24 编辑:简简单单 来源:一聚教程网
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);
}
}
-
上一个: php 导入excel文档程序
-
下一个: php 日期转换成日时截
相关文章
- php 超大文件下载程序[http 缓存协商,Etag标记,断点续传] 04-11
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24