PHP:缓存整洁的解析字符串
在我的页面顶部,我有这段代码来检查缓存并启动输出缓冲:
ob_start( );
$cache_time = 3600;
$cache_folder = $_SERVER['DOCUMENT_ROOT'].'/cache';
$cache_filename = $cache_folder.md5($_SERVER['REQUEST_URI']);
$cache_created = (file_exists($cache_filename)) ? filemtime($cache_filename->filename) : 0;
if ((time() - $cache_created) < $cache_time) {
readfile($cache_filename);
die();
}
然后在底部我用它来整理输出缓冲区并缓存页面,但似乎没有任何内容被缓存......
$html = ob_get_clean();
$config = array('indent' => TRUE,
'drop-empty-paras' => FALSE,
'output-xhtml' => TRUE,
'quote-ampersand' => TRUE,
'indent-cdata' => TRUE,
'tidy-mark' => FALSE,
'wrap' => 200);
$tidy = tidy_parse_string($html, $config, 'UTF8');
file_put_contents($cache_filename, $tidy);
echo $tidy;
任何人都知道什么做什么?
At the top of my page I have this piece of code to check cache and initiate output buffering:
ob_start( );
$cache_time = 3600;
$cache_folder = $_SERVER['DOCUMENT_ROOT'].'/cache';
$cache_filename = $cache_folder.md5($_SERVER['REQUEST_URI']);
$cache_created = (file_exists($cache_filename)) ? filemtime($cache_filename->filename) : 0;
if ((time() - $cache_created) < $cache_time) {
readfile($cache_filename);
die();
}
Then at the bottom I use this to tidy the output buffer and cache the page, but it nothing appears to be cached...
$html = ob_get_clean();
$config = array('indent' => TRUE,
'drop-empty-paras' => FALSE,
'output-xhtml' => TRUE,
'quote-ampersand' => TRUE,
'indent-cdata' => TRUE,
'tidy-mark' => FALSE,
'wrap' => 200);
$tidy = tidy_parse_string($html, $config, 'UTF8');
file_put_contents($cache_filename, $tidy);
echo $tidy;
Anyone know what to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码中存在一些错误:
我像这样修复它们的值,以php 手册页:
There were some errors in your code:
I fixed them like so, taking the example of the php manual page: