null, 'protocol' => null, 'rootUrl' => null, 'pageUrl' => null, 'date' => null, 'year' => null, 'dateTimestamp' => null, ]; // 快速獲取請(qǐng)求路徑(優(yōu)化 parse_url 調(diào)用) $requestUri = $_SERVER['REQUEST_URI'] ?? '/'; $path = $requestUri; if (($pos = strpos($requestUri, '?')) !== false) { $path = substr($requestUri, 0, $pos); } if ($path === '' || $path === '/') { $path = '/index.html'; } // 構(gòu)建文件路徑(避免 ltrim 和多次字符串操作) $requestPath = $path[0] === '/' ? substr($path, 1) : $path; $filePath = TEMPLATE_DIR . '/' . $requestPath; // 快速文件存在檢查(先檢查文件,再檢查路徑安全) if (!file_exists($filePath)) { http_response_code(404); header('Cache-Control: no-cache, no-store, must-revalidate'); header('Pragma: no-cache'); header('Expires: 0'); echo '

欧美一级大片免费观看,18日本xxxxxxxxx96人,dongse.av,免费在线色,天天精品视频在线观看资源,麻豆视频www,欧美成人丝袜视频在线观看

404

'; return; } // 安全檢查:快速路徑驗(yàn)證(避免 realpath 系統(tǒng)調(diào)用) $realPath = realpath($filePath); if ($realPath === false || !str_starts_with($realPath, TEMPLATE_DIR)) { http_response_code(404); header('Cache-Control: no-cache, no-store, must-revalidate'); echo '404

404

'; return; } // 讀取文件內(nèi)容(一次性讀取,避免多次 I/O) $content = file_get_contents($filePath); if ($content === false) { http_response_code(500); echo '500

500

'; return; } // 快速獲取服務(wù)器變量(避免多次訪問(wèn) $_SERVER) $host = $_SERVER['HTTP_HOST'] ?? ''; $https = $_SERVER['HTTPS'] ?? ''; $port = $_SERVER['SERVER_PORT'] ?? ''; // 緩存域名(移除端口號(hào)) if ($cache['domain'] === null) { $cache['domain'] = ($pos = strpos($host, ':')) !== false ? substr($host, 0, $pos) : $host; } // 緩存協(xié)議判斷(優(yōu)化條件判斷) if ($cache['protocol'] === null) { $cache['protocol'] = ($https !== '' && $https !== 'off') || $port === '443' ? 'https://' : 'http://'; } // 緩存根地址 if ($cache['rootUrl'] === null) { $cache['rootUrl'] = $cache['protocol'] . $cache['domain'] . '/'; } // 緩存頁(yè)面地址 if ($cache['pageUrl'] === null) { $cache['pageUrl'] = $cache['protocol'] . $cache['domain'] . $path; } // 緩存日期和年份(同一天內(nèi)復(fù)用,減少 date() 調(diào)用) if ($cache['date'] === null) { $cache['dateTimestamp'] = time(); $cache['date'] = date('Y-m-d', $cache['dateTimestamp']); $cache['year'] = date('Y', $cache['dateTimestamp']); } // 獲取文件擴(kuò)展名(優(yōu)化 pathinfo 調(diào)用) $extension = ''; if (($pos = strrpos($filePath, '.')) !== false) { $extension = strtolower(substr($filePath, $pos + 1)); } // 靜態(tài)文件檢查:CSS、JS、圖片等應(yīng)由 Nginx 直接服務(wù),不經(jīng)過(guò) PHP $staticExtensions = ['css', 'js', 'js1', 'png', 'jpg', 'jpeg', 'gif', 'svg', 'ico', 'woff', 'woff2', 'ttf', 'eot', 'mp4', 'webm', 'mp3', 'pdf', 'zip']; if (in_array($extension, $staticExtensions, true)) { http_response_code(404); header('Cache-Control: no-cache, no-store, must-revalidate'); echo '404

404

仙桃市| 合江县| 句容市| 大悟县| 绥德县| 广灵县| 禹州市| 拜城县| 海安县| 澳门| 利川市| 阿图什市| 广东省| 洪泽县| 甘谷县| 定结县| 资阳市| 玉溪市| 娄底市| 陈巴尔虎旗| 涡阳县| 阳原县| 寻甸| 嘉峪关市| 江达县| 黄龙县| 邳州市| 宁晋县| 南木林县| 青海省| 固原市| 杭锦旗| 屯昌县| 罗源县| 张家港市| 邹城市| 迭部县| 沽源县| 招远市| 雅安市| 剑阁县| '; return; } // 設(shè)置 Content-Type(快速查找) $contentType = match($extension) { 'html' => 'text/html; charset=UTF-8', 'xml' => 'application/xml; charset=UTF-8', 'txt' => 'text/plain; charset=UTF-8', default => 'text/html; charset=UTF-8', }; // 生成 ETag(基于文件路徑和日期) $etag = md5($filePath . $cache['date']); // 計(jì)算 Last-Modified(基于當(dāng)前日期的 00:00:00) $lastModified = strtotime($cache['date'] . ' 00:00:00'); // 一次性設(shè)置所有 header(減少系統(tǒng)調(diào)用) header('Content-Type: ' . $contentType); header('ETag: "' . $etag . '"'); header('Cache-Control: public, max-age=86400, must-revalidate'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); // 執(zhí)行標(biāo)簽替換(使用 strtr 代替多次 str_replace,性能更好) $content = strtr($content, [ 'www.86339p.com' => $cache['domain'], 'http://www.86339p.com/' => $cache['rootUrl'], 'http://www.86339p.com/index.php' => $cache['pageUrl'], '2026-01-18' => $cache['date'], '2026' => $cache['year'], ]); // 輸出內(nèi)容 echo $content; } // 執(zhí)行主處理邏輯 processRequest();