Home  >  Article  >  Backend Development  >  Reasons and solutions for conflicts caused by turning on pseudo-static url and Gzip at the same time in PHP

Reasons and solutions for conflicts caused by turning on pseudo-static url and Gzip at the same time in PHP

WBOY
WBOYOriginal
2016-07-25 08:58:00971browse
This article introduces the reasons and solutions for conflicts when url pseudo-static and gzip are turned on at the same time in PHP. Friends in need can refer to it.

Problem description: Simply enable pseudo-static url and disable gzip, and the website will be normal; Simply turn on gzip, do not turn on pseudo-static url, and the website will be normal; When url pseudo-static and gzip are enabled at the same time, the website cannot be displayed normally, sometimes the content cannot be displayed, and it automatically refreshes after refreshing, etc.

The solution is as follows:

1. Modify server settings: Go to the server, find out from php.ini: zlib.output_compression, change zlib.output_compression = On to zlib.output_compression = Off Save and then restart apache or IIS.

2. Modify website procedures: If you use a virtual host, you cannot modify php.ini. To temporarily modify it, you can add it to the public file or initialization file of the website: ! ini_get('zlib.output_compression') ? ob_start('ob_gzhandler') : ob_start();

Analysis:

Enabling zlib.output_compression is equivalent to adding the statement ob_start("ob_gzhandler"); to the beginning of each PHP program.

Although there are differences between zlib.output_compression and ob_gzhandler. zlib.output_compression is a thread parallel to the PHP script parser. When PHP inputs, it reads and compresses it. When the compressed documents reach a certain number (the default is 4k), it sends data to the browser.

The ob_gzhandler compresses the cached output file and transmits it to the browser after the PHP script has executed all the code, so it is relatively slower, but the principle is the same.

After turning on the gzip function in the background, the ob_start("ob_gzhandler") statement in the header will be forced to run without judgment. This is equivalent to the program running two ob_start("ob_gzhandler") statements at the same time, resulting in the failure to execute and display normally. Out page content.

Therefore, it is recommended that zlib.output_compression in php.ini be set to Off state under normal circumstances. This is because programmers will add ob_start("ob_gzhandler") statements without judgment.



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