PHP開啟Gzip頁面沒有輸出的解決方案

來源:互聯網
上載者:User
  1. output_buffering = Off
  2. output_handler =
  3. zlib.output_compression = On
複製代碼

即可實現為全站的php檔案啟用gzip加速。

對於html檔案,可以通過配置.htaccess檔案,由php來處理html請求(會加重伺服器負擔,建議在nginx或apache上做gzip處理):

  1. AddHandler x-httpd-php .html .htm
複製代碼

問題:預設安裝的PHP5.3,一旦開啟了Gzip壓縮輸出功能,開啟網站首頁會無法顯示。這是由於PHP配置有問題造成的,5.3預設配置如下:output_buffering=4096; 將其設定為off或者0即可解決。

經過驗證,這個問題在PHP 5.1 - PHP5.2中都存在。

不用擔心是否影響壓縮,或根本就不壓縮,可以用如下的方法判斷:

  1. curl -I --compressed http://bbs.it-home.org
複製代碼

HTTP/1.1 200 OKServer: nginx/0.8.13Date: Tue, 01 Sep 2009 16:38:53 GMTContent-Type: text/htmlConnection: keep-aliveVary: Accept-EncodingX-Powered-By: PHP/5.2.10Expires: Mon, 26 Jul 1997 05:00:00 GMTLast-Modified: Tue, 01 Sep 2009 16:38:53 GMTCache-Control: no-store, no-cache, must-ridatePragma: no-cacheContent-Encoding: gzip

如果結果中有:Content-Encoding: gzip 這句,則說明該網頁是經gzip壓縮過的,即php gzip壓縮有效。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.