Home  >  Article  >  Backend Development  >  Solution to the problem of no output when Gzip page is enabled in PHP

Solution to the problem of no output when Gzip page is enabled in PHP

WBOY
WBOYOriginal
2016-07-25 08:58:581112browse
  1. output_buffering = Off
  2. output_handler =
  3. zlib.output_compression = On
Copy the code

to enable gzip acceleration for the entire site's php files.

For html files, you can configure the .htaccess file and let php handle html requests (it will increase the load on the server. It is recommended to do gzip processing on nginx or apache):

  1. AddHandler x-httpd-php .html .htm
Copy code

Question: PHP5.3 installed by default, once the Gzip compression output function is turned on, the homepage of the website will not be displayed. This is caused by a problem with PHP configuration. The default configuration in 5.3 is as follows: output_buffering=4096; Set it to off or 0 to solve the problem.

It has been verified that this problem exists in PHP 5.1 - PHP5.2.

Don’t worry about whether it will affect compression or not compress at all. You can use the following method to judge:

  1. curl -I --compressed http://bbs.it-home.org
Copy code

HTTP/1.1 200 OK Server: nginx/0.8.13 Date: Tue, 01 Sep 2009 16:38:53 GMT Content-Type: text/html Connection: keep-alive Vary: Accept-Encoding X-Powered-By: PHP/5.2.10 Expires: Mon, 26 Jul 1997 05:00:00 GMT Last-Modified: Tue, 01 Sep 2009 16:38:53 GMT Cache-Control: no-store, no-cache, must-ridate Pragma: no-cache Content-Encoding: gzip

If the result contains the sentence: Content-Encoding: gzip, it means that the webpage is gzip compressed, that is, php gzip compression is effective.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn