In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to control the PHP output cache and compress dynamic pages. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Mod_gzip is an Apache module whose function is to use Gzip to compress static html pages. Browsers that follow IETF standards can accept gzip encoding (IE, Netscape, etc.). Mod_gzip can increase the download time of the page by 4-5 times. I strongly recommend that you use mod_gzip on your web server. However, we must also build our own compression engine using PHP. In this article, I will show you how to use PHP's output control function to greatly speed up page loading.
Introduce the output control function of PHP
The most satisfying thing about PHP4 is that you can have PHP cache all the output generated by the script, and the browser won't receive anything until you decide to send them out. You can use these functions to set up header and cookies in scripting programs, but this is only a small part of the powerful output function.
The copy code is as follows:
Tells the PHP processor to redirect all output to an internal buffer. Before calling ob_start, no output is sent to the browser.
The copy code is as follows:
This function returns the output cache (output buffer) as a string. You can call this function to send the accumulated output to the browser. (only after turning off the buffering function! )
The copy code is as follows:
Returns the length of the string in the cache.
The copy code is as follows:
Clear the output cache and turn it off. You must use this function before the contents of the cache can be output to the browser.
Void 501 ([int flag])
Used to turn on / off the implied flush action switch (the default is off). If flush is on, each time print/echo or other output command is called, the output will be sent to the browser immediately.
Use output control to compress PHP output
You must use the Zlib extension package compiled in PHP4 to compress the output. If necessary, check the installation instructions for the Zlib package in the PHP documentation.
First, initialize the output cache:
The copy code is as follows:
After that, generate all the output using print, echo, or any other method you like, such as:
The copy code is as follows:
After the page is generated, we retrieve the output:
The copy code is as follows:
After that, you must test whether the browser supports compressed data. If supported, the browser sends an ACCEPT-ENCODEING HTTP header to the server. We just need to check if there is a "gzip,deflate" string in the $HTTP_ACCEPT_ENCODING variable.
The copy code is as follows:
This method is simple to use and clear in structure. Let's look at how to generate compressed output:
The copy code is as follows:
/ / well, you can also attach more compressed data in this way.
To actually test, all the script code is as follows:
The copy code is as follows:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.