Share two ways to compress page output data to improve page access speed by using PHP zlib Extensions for page gzip compression output (using PHP's built-in function Ob_gzhandler for gzip compression output), Another way is to modify the php.ini configuration file to open PHP gzip to achieve compressed page information compression transmission, and now to share in detail how these two methods are implemented separately!
(1) gzip compression output via PHP's built-in function Ob_gzhandler
Add the following code to the head of the page:
if (extension_loaded (' zlib ') && strstr ($_server[' http_accept_encoding '], ' gzip ')) { Ob_start (' Ob_ Gzhandler ');} else{ exit (' PHP zlib use failed, please verify that the zlib extension is loaded ');}
Add the following code at the end of the page:
if (extension_loaded (' zlib ')) {Ob_end_flush ();}
The following are two websites that access different domain names but have exactly the same information, the results are as follows:
(2) To enable or disable PHP gzip by modifying the php.ini configuration file to compress the page information compressed transmission
First, locate and open the PHP.ini configuration file, locate zlib.output_compression = Off, and
Zlib.output_compression = Off ; zlib.output_compression_level =-1
Modified to:
Zlib.output_compression = on zlib.output_compression_level = 6
PHP gzip Configuration Knowledge Points:
1, the default PHP is not open zlib entire station compression output, but by the need to compress the output of the page using the Ob_gzhandler function, the two can only two select one, or will error.
2, zlib.output_compression default value is off, you can set it to on, or output buffer size (default is 4k)
3, Zlib.output_compression_level represents the compression ratio, the default recommended setting compression ratio of 6, the optional range of 1-9,-1 for closing PHP zlib (gzip) compression
Second, save php.ini configuration file and restart Apache server
Third, open the Apache configuration file httpd.conf, configure the Mount Deflate_module. This step is the most critical to open the PHP gzip compression output configuration step, as follows, find
#LoadModule Deflate_module modules/mod_deflate.so
This section and remove the # number from the beginning, then restart Apache.
Note: This method is relative to PHP version larger than 4.3来 said, php4.3 version of the previous need to install zlib separately. In addition I use Phpnow built PHP server, directly modify the php.ini (Phpnow PHP related options configuration file is Php-apache2handler.ini) related configuration and restart Apache, do not need a second step.
The following are two websites that access different domain names but have exactly the same information, the results are as follows:
Specific to see the effect can be viewed in Firefox browser, right click on the page, pop-up menu has a view page information options, pop-up window to see the size of that one. I do not have the website to implement the function, sad that I do not support the space gzip compression function, code can not be achieved!
Articles you may be interested in
- Compress website js and CSS files using PHP's gzip compression to speed up website access
- How to use zlib to compress output content to improve Web page opening speed
- Add a Site collection icon to a Web site
- PHP compressed HTML page code reduces network data transfer, clear spaces, tabs, comment tags
- Shoulder, back muscle workout-pull up-bow row-prone to rise-standing posture weight leaning bent up-seated neck drop-down-sit at attention grip pull-neck width grip upward
- It's dangerous to have access to the same content on a variety of URLs on the site.
- How to optimize Web pages to increase the load speed of Web pages
- MySQL Reference Architecture from small websites to hyper-scale websites
http://www.bkjia.com/PHPjc/764196.html www.bkjia.com true http://www.bkjia.com/PHPjc/764196.html techarticle sharing two ways to compress page output data to improve Web page access, one is to implement page gzip compression output using PHP zlib extensions (using PHP's built-in function Ob_gzhandler ...