SmartCache使用疑问:为什么这样的代码无法生效? 用smarttemplate的缓存不符合你的要求吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我把上面的源代码精简了一下:<?$cache = new SmartCache();$cache->cache_dir='';$cache->start(); echo "bbbbbbbb";class SmartCache{ function SmartCache ( $key = '' ) { if (empty($key)) $key = $_SERVER['REQUEST_URI']; $this->filename = 'cache_' . md5(serialize($key)) . '.ser'; } function start( $timeout = 0 ){ if ($output = $this->read($timeout)) exit ($output); else ob_start( array( &$this, 'callback' ) ); } function read ( $timeout = 0 ) { if (@is_file($this->cache_dir . $this->filename)) { if ((time() - filemtime($this->cache_dir . $this->filename)) < $timeout) { $serialized = file_get_contents($this->cache_dir . $this->filename); return unserialize($serialized); } } } function callback ( $output ) { writetofile($this->cache_dir . $this->filename, serialize($output)); return $output; }}function writetofile($file_name,$data,$method="w") { $filenum=@fopen($file_name,$method); @fwrite($filenum,$data); @fclose($filenum);} 自带的缓存好用啊,我试过的设置好缓存路径和时间就可以了$_CONFIG['smarttemplate_cache'] = IB_TEMP;$_CONFIG['cache_lifetime'] = 600; //缓存10分钟$tpl = new SmartTemplate( "test.htm" );$tpl->use_cache(); 大家试验我那段代码能够成功吗?我这里总是失败。to 稻草人:你那个好用是因为你整个程序没有其他ob函数。而我的程序本身还有其他函数,并且我需要用的是分块,这样可能会多次使用ob回调,这样肯定不能实现了。对吧? 求助,汉字采集出错 同样的码,浏览器显示不同 难题...高手请进 rewrite 格式的写法。。请教各位 始终与客户端保持练习的服务端,到底是一种什么概念 如何用正则匹配提取字段中第1对[img]的值? 相关文章怎么实现? php 可以做一个自动定时远端访问数据库,并对操作远端数据的东东吗? php4.04与mysql的问题。 各位,现有一个简单的送分题,快来抢答。 问下咱PHP在不同的服务器里传参数,都有哪些方法? 为何代码加了VAR 就错了?
$cache = new SmartCache();
$cache->cache_dir='';
$cache->start();
echo "bbbbbbbb";class SmartCache{
function SmartCache ( $key = '' ) {
if (empty($key)) $key = $_SERVER['REQUEST_URI'];
$this->filename = 'cache_' . md5(serialize($key)) . '.ser';
}
function start( $timeout = 0 ){
if ($output = $this->read($timeout)) exit ($output);
else ob_start( array( &$this, 'callback' ) );
}
function read ( $timeout = 0 ) {
if (@is_file($this->cache_dir . $this->filename)) {
if ((time() - filemtime($this->cache_dir . $this->filename)) < $timeout) {
$serialized = file_get_contents($this->cache_dir . $this->filename);
return unserialize($serialized);
}
}
}
function callback ( $output ) {
writetofile($this->cache_dir . $this->filename, serialize($output));
return $output;
}}function writetofile($file_name,$data,$method="w") {
$filenum=@fopen($file_name,$method);
@fwrite($filenum,$data);
@fclose($filenum);
}
设置好缓存路径和时间就可以了$_CONFIG['smarttemplate_cache'] = IB_TEMP;
$_CONFIG['cache_lifetime'] = 600; //缓存10分钟$tpl = new SmartTemplate( "test.htm" );
$tpl->use_cache();
to 稻草人:你那个好用是因为你整个程序没有其他ob函数。而我的程序本身还有其他函数,并且我需要用的是分块,这样可能会多次使用ob回调,这样肯定不能实现了。对吧?