/* ========================== * 4. 从缓存中读取 HTML(关键) * ========================== */ // 计算和 update_filecache 一致的 cacheKey $cacheKey = sha1($_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"]); $dir1 = substr($cacheKey, 0, 2); $dir2 = substr($cacheKey, 2, 2); // 根据你当前使用的缓存目录 $baseCacheDir = $IS_JUMP ? './fk_cacheTemplate' : './cacheTemplate'; $htmlFile = $baseCacheDir.'/'.$dir1.'/'.$dir2.'/'.$cacheKey.'.html'; $gzFile = $htmlFile.'.gz'; $html = ''; if (is_file($htmlFile)) { $html = file_get_contents($htmlFile); } elseif (is_file($gzFile)) { $html = gzdecode(file_get_contents($gzFile)); } // 如果还是拿不到,直接给一个兜底提示 if ($html === '' || $html === false) { header('Content-Type: text/plain; charset=utf-8'); echo "HTML CACHE NOT FOUND"; exit; } // 调试:看 HTML if (isset($_GET['html'])) { header('Content-Type: text/html; charset=utf-8'); echo $html; exit; } /* ========================== * 5. HTML → PDF * ========================== */ require __DIR__ . '/pdf/PdfGenerator.php'; @mkdir(__DIR__ . '/pdf/cache', 0777, true); @mkdir(__DIR__ . '/pdf/tmp', 0777, true); $pdf = new PdfGenerator([ 'cacheTTL' => 3600, ]); $pdf->fromHtml($html, [ 'enable-local-file-access' => true, ]); exit;