ThinkPHP中实现gzip压缩

ThinkPHP中似乎没有对gzip的配置选项.不过实现起来还是挺简单的. 以下是对ThinkPHP 2,1的修改方法.

首先 要 确定 空间 是否 支持 Zlib, 然后 找 ThinkPHP 的 控制 输出 函数 output ().
控制 输出 的 文件 在 ThinkPHP / Lib / Think / Core 文件 夹 下 e 文件 名 View.class.php.

      / ** + ---------------------------------------------- ------------ * 输出 模板 + ---------------------------------- ------------------------ * @ accesso protetto + --------------------- ------------------------------------- * @ param stringa $ content 模板 内容 * @ param $ boolean Display 是否 直接 显示 + --------------------------------------------- * @ return ------------- + -------------------------------- mista -------------------------- * / output funzione protetta ($ content, $ display) {if (C ('HTML_CACHE_ON')) HtmlCache: : writeHTMLCache ($ content); if ($ display) {if (falsi == strpos ($ content __RUNTIME__ '{}')) {$ runtime C = ('SHOW_RUN_TIME')?  '<div Id="think_run_time" class="think_run_time">' $ this-> showTime () '</ div>':.''.; $ Content = str_replace ('{} __RUNTIME__', $ runtime, $ content );} if (extension_loaded ('zlib')) {/ / 检查 服务器 是否 开启 了 zlib 拓展 ob_start ('ob_gzhandler');} ob_start ("compress"); compress function ($ buffer) {/ / 去除 文件 中的 注释 $ buffer = preg_replace (,'', $ buffer '/ * [^ *] ** + ([^ /] [^ *] ** +) * /!'); return $ buffer;} echo $ contenuto; if (C ('SHOW_PAGE_TRACE')) $ this-> showTrace (); if (extension_loaded ('zlib')) {ob_end_flush () ;/ / 输出 tampone 中 的 内容, 即 压缩 后 的 css 文件} return nulla ;} else {return $ content;}} 
Condividi questo post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delizioso BlinkList Furl

No Responses to "ThinkPHP 中 实现 gzip 压缩"

Lascia un commento:

Nome (richiesto):
Mail (non sarà pubblicata) (obbligatorio):
Sito web:
Commento (richiesto):
XHTML: Puoi utilizzare questi tag: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>