使用方法: " /> 少妇被躁爽到高潮无码久久,亚洲国产AV精品卡一卡二,最近中文字幕高清中文字幕MV

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

PHP版網站緩存加快打開速度的方法分享

說明:
1,在服務器緩存了壓縮過的文件,再次訪問減少再壓縮時間,降低CPU占用率。
2,通過設置客戶端文件緩存時間,降低再次請求次數,可降低85%以上。
3,圖片因為已經是壓縮格式,只是設置客戶端緩存時間,不做壓縮處理。

使用方法:
1,服務器必須支持gzip,Rewrite功能。
2,在.htacess文件的“RewriteBase /”下面一行添加下面的代碼,見圖
RewriteRule (.*.css$|.*.js$|.*.jpg$|.*.gif$|.*.png$) gzip.php?$1 [L]
3,上傳gzip.php到根目錄
4,在根目錄建cache文件夾,保證可讀寫。


復制代碼 代碼如下:
<?php
/**
* @author Seraphim
* @copyright 2012
*/
// <!-- 公共的返回header的子程序 -->
function sendheader($last_modified, $p_type, $content_length = 0)
{
// 設置客戶端緩存有效時間
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 15360000) . "GMT");
header("Cache-Control: max-age=315360000");
header("Pragma: ");
// 設置最后修改時間
header("Last-Modified: " . $last_modified);
// 設置文件類型信息
header($p_type);
header("Content-Length: " . $content_length);
}
define('ABSPATH', dirname(__file__) . '/');
$cache = true;
$cachedir = 'cache/'; //存放gz文件的目錄,確保可寫
if (empty($_SERVER['QUERY_STRING']))
exit();
$gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
if (empty($gzip))
$cache = false;
$key = array_shift(explode('?', $_SERVER['QUERY_STRING']));
$key = str_replace('../', '', $key);
$filename = ABSPATH . $key;
$symbol = '_';
$rel_path = str_replace(ABSPATH, '', dirname($filename));
$namespace = str_replace('/', $symbol, $rel_path);
$cache_filename = ABSPATH . $cachedir . $namespace . $symbol . basename($filename) .
'.gz'; //生成gz文件路徑
$ext = array_pop(explode('.', $filename)); //根據后綴判斷文件類型信息
$type = "Content-type: text/html"; //默認的文件類型
switch ($ext)
{
case 'css':
$type = "Content-type: text/css";
break;
case 'js':
$type = "Content-type: text/Javascript";
break;
case 'gif':
$cache = false;
$type = "Content-type: image/gif";
break;
case 'jpg':
$cache = false;
$type = "Content-type: image/jpeg";
break;
case 'png':
$cache = false;
$type = "Content-type: image/png";
break;
default:
exit();
}
if ($cache)
{
if (file_exists($cache_filename))
{ // 假如存在gz文件
$mtime = filemtime($cache_filename);
$gmt_mtime = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
if ((isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && array_shift(explode(';', $_SERVER['HTTP_IF_MODIFIED_SINCE'])) ==
$gmt_mtime))
{
// 與瀏覽器cache中的文件修改日期一致,返回304
header("HTTP/1.1 304 Not Modified");
// 發送客戶端header
header("Content-Encoding :gzip");
sendheader($gmt_mtime, $type);
}
else
{
// 讀取gz文件輸出
$content = file_get_contents($cache_filename);
// 發送客戶端header
sendheader($gmt_mtime, $type, strlen($content));
header("Content-Encoding: gzip");
// 發送數據
echo $content;
}
}
else
if (file_exists($filename))
{ // 沒有對應的gz文件
$mtime = mktime();
$gmt_mtime = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
// 讀取文件
$content = file_get_contents($filename);
// 去掉空白的部分
// $content = ltrim($content);
// 壓縮文件內容
$content = gzencode($content, 9, $gzip ? FORCE_GZIP : FORCE_DEFLATE);
// 發送客戶端header
sendheader($gmt_mtime, $type, strlen($content));
header("Content-Encoding: gzip");
// 發送數據
echo $content;
// 寫入文件
file_put_contents($cache_filename, $content);
}
else
{
header("HTTP/1.0 404 Not Found");
}
}
else
{ // 處理不使用Gzip模式下的輸出。原理基本同上
if (file_exists($filename))
{
$mtime = filemtime($filename);
$gmt_mtime = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
if ((isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && array_shift(explode(';', $_SERVER['HTTP_IF_MODIFIED_SINCE'])) ==
$gmt_mtime))
{
// 與瀏覽器cache中的文件修改日期一致,返回304
header("HTTP/1.1 304 Not Modified");
// 發送客戶端header
sendheader($gmt_mtime, $type, strlen($content));
header("Content-Encoding :gzip");
}
else
{
// 讀取文件輸出
$content = file_get_contents($filename);
// 發送客戶端header
sendheader($gmt_mtime, $type, strlen($content));
// 發送數據
echo $content;
}
}
else
{
header("HTTP/1.0 404 Not Found");
}
}
?>

php技術PHP版網站緩存加快打開速度的方法分享,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 久久www免费人成_看片高清 | av视频在线免播放观看 | 午夜伦理伦理片在线观 | 一个人在线观看视频免费 | 92精品国产成人观看免费 | 亚洲高清国产品国语在线观看 | 99re这里只有精品视频 | 俄罗斯美女z0z0z0在线 | 5g在视影讯天天5g免费观看 | 亚洲一区二区三区高清网 | 欧美18videosex | 无止侵犯高H1V3无止侵犯 | 国产精品久久自在自2021 | 99久久免费热在线精品 | 99久久精品免费看国产一区二区三区 | 欧美2019高清hd巨大 | 日韩插啊免费视频在线观看 | 成人国产AV精品久久久久 | 日韩爽爽影院在线播放 | 少爷被多个暗卫肉高h | 2020年国产理论 | 国产精品久久久久影院嫩草 | 国语自产一区第二页 | 国产 亚洲 日韩 欧美 在线观看 | 把腿张开JI巴CAO死你H教室 | 亚洲高清有码中文字 | 亚洲综合无码一区二区 | 男人都懂www深夜免费网站 | 欧美大片免费观看 | 国产极品美女视频福利 | 好姑娘BD高清在线观看免费 | 亚洲 日本 中文字幕 制服 | 少妇高潮久久久久7777 | WWW污污污抽搐喷潮COM | 国产精品嫩草影院在线观看免费 | 在教室做啊好大用力 | 亚洲国产亚综合在线区尤物 | AV天堂午夜精品一区 | 办公室韩国电影免费完整版 | 全部免费特黄特色大片看片 | 精品国产午夜福利在线观看蜜月 |