date_default_timezone_set('PRC'); // 生成缓存文件名,保持原样逻辑[cite: 5, 6] $cachefile = "cache/" . sha1($_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]) . ".cache"; ob_start(); // 1. 读取缓存部分修改 if (file_exists($cachefile)) { // 【关键修改】:因为存的是 Gzip 压缩数据,不能用 include,改用 readgzfile 极速解压输出 readgzfile($cachefile); ob_end_flush(); exit; } // 这里引入你的解析文件,文章页用 article.php[cite: 5],列表页用 list.php[cite: 6] include "966seo/article.php"; echo $moban; //[cite: 5, 6] // 获取缓冲区内容[cite: 5, 6] $info = ob_get_contents(); // 2. 源码级压缩:去除 HTML 注释、回车、换行、制表符、多余空格 $info = preg_replace( array('//is', "/\r\n/", "/\r/", "/\n/", "/\t/", '/\s+/'), array('', '', '', '', '', ' '), $info ); // 3. 物理级压缩:使用 gzencode 进行级别 9 的最高压缩 $compressed_info = gzencode($info, 9); // 写入缓存文件,保持原有的目录判断逻辑[cite: 5, 6] if (is_dir("cache")) { file_put_contents($cachefile, $compressed_info); ob_end_flush(); // 规范化:建议加一句闭合缓冲 exit; } if (!@mkdir("cache")) { ob_end_flush(); // 规范化 exit; } file_put_contents($cachefile, $compressed_info); ob_end_flush(); // 规范化