Php ob_get_内容出现问题-返回无法读取的内容
我想创建一个缓存。在我的php索引开始时,我使用:Php ob_get_内容出现问题-返回无法读取的内容,php,caching,ob-get-contents,Php,Caching,Ob Get Contents,我想创建一个缓存。在我的php索引开始时,我使用: if ($docache) { $folder_cache = dirname(__FILE__).'/cache/'; $seconds_cache = 15*60; // 15 minutes $url_cache = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $file_cache = $folder_cache . md5($url_cache) .
if ($docache) {
$folder_cache = dirname(__FILE__).'/cache/';
$seconds_cache = 15*60; // 15 minutes
$url_cache = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$file_cache = $folder_cache . md5($url_cache) . '.cache';
$file_cache_existe = ( @file_exists($file_cache) ) ? @filemtime($file_cache) : 0;
if ($file_cache_existe > time() - $seconds_cache ) {
@readfile($file_cache);
exit();
}
}
ob_start();
然后,最后:
if ($docache) {
$folder_cache = dirname(__FILE__).'/cache/';
$url_cache = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$file_cache = $folder_cache . md5($url_cache) . '.cache';
$filehandler = @fopen($file_cache, 'w');
@fwrite($filehandler, ob_get_contents());
@fclose($filehandler);
}
好吧,它起作用了。。。缓存文件是在我们第一次看到页面时创建的,然后我们返回,它在缓存中显示文件。。。问题是缓存中的文件只包含一些不可读的字符,如�� 您可以从移除错误抑制并检查输出内容开始
很可能您遇到了字符编码问题。
问题是缓存中的文件只包含一些不可读的字符,如
,那么,它应该包含什么?它应该包含页面显示时的HTML代码。好的,在Google上使用此功能搜索字符编码问题,我发现问题是由于我使用的gzip压缩。禁用时,效果良好。我会努力让他们一起工作。非常感谢。