- Output_buffering = Off
-
3. php. ini is
- ; Output_handler = ob_gzhandler
- Zlib. output_compression = Off
- ; Zlib. output_compression_level =-1
-
4. Add apache as follows:
-
- AddOutputFilter DEFLATE html php js css
Method 2: Use zlib. output_compression1 in php. ini to disable mod_deflate.so2 and php. ini in apache:
- Output_buffering = On
-
2. php. ini is
- ; Output_handler =
- Zlib. output_compression = Off
- Zlib. output_compression_level = 6 (Level-1 to 9, 6 by default)
Method 3: Use the php built-in function ob_gzhandler (php_zlib.dll must be installed and enabled in extension) 1, disable mod_deflate.so2 in apache, and php. ini is
- Output_handler = ob_gzhandler
- Zlib. output_compression = On
- ; Zlib. output_compression_level =-1
Note: If php is used in method 3. if output_handler = ob_gzhandler is set in ini, you do not need to add ob_start ('OB _ gzhandler ') to the program. Otherwise, the program will compress the data and report an error. the general program will judge it. Set php. ini to disabled by default, and add it to the program. if it is your own server, set ini to enabled by default. We recommend that you use 1st or 2nd types: (1st types are recommended) in this case, ob_start () can be used to customize functions, such as: ob_start ("compress_html"); to compress the html format:
- Function compress_html ($ buffer) {// remove comments from the file
- $ Pattern = array ("/> * ([^] *) * /"," '/\ * [^ *] * \ */' ","/[\ S] +/","/\ r \ n /", "/\ n/", "/\ t /");
- $ Replace = array (">\\ 1 <","","","","","","");
- Return ltrim (rtrim (preg_replace ($ pattern, $ replace, $ buffer )));
- }
-
After that, you can not only compress the html format (but also use gzip ). Complete configuration scheme of Method 1: 1. open mod_deflate.so2 in apache, and set php. ini
- Output_buffering = Off
-
3. php. ini is;
- Output_handler = ob_gzhandler
- ; Zlib. output_compression = Off
- ; Zlib. output_compression_level =-1
-
4. Add apache as follows:
-
- AddOutputFilter DEFLATE html php js css
Use the following program to compress the php header in html format:
- Ob_start ("compress_html"); // you need to enable zlib. output_compression in php. ini.
- Function compress_html ($ buffer) {// remove comments from the file
- $ Pattern = array ("/> * ([^] *) * /"," '/\ * [^ *] * \ */' ","/[\ S] +/","/\ r \ n /", "/\ n/", "/\ t /");
- $ Replace = array (">\\ 1 <","","","","","","");
- Return ltrim (rtrim (preg_replace ($ pattern, $ replace, $ buffer )));
- }
-
In this way, php's gzip compression function is enabled, and html is automatically compressed and formatted when the browser views the source file, which is very useful. Enable gzip compression, especially for low-cost webmasters, bandwidth is white. |