|
| |
|
|
BobbyDouglas
Posts: 5479 Joined: 5/15/2003 From: Arizona Status: offline
|
Compress your pages! (Average up to 80%) - 4/29/2005 17:59:39
Here is a neat trick that will compress your pages. This compresses text only, and does not include images/flash/etc. This saves bandwith by sending compressed pages to the user, and is very easy on the server. This has only been tested on Linux/Unix servers. If you are Windows, there is a service that offers Compression for Windows. FAQ (Detailed page explaining the process of compression) Q. What is compression? A. Compression is similar to programs such as WinZip, and WinRar that compress files into .zip format. However in this article, compression is done much faster. Q. What exactly happens? A. The server (place the website is on), receives a request for the page (Someone comes along and says, hey give me that file!), after it receives the request, it compresses the file, and then sends the compressed file. The browser (of the person who requested the file) will automatically unzip the compressed file. Q. Will this slow down my computer? A. No. Q. How do I tell if this will work on my browser? A. All of the most common browser do this automatically. If you are not sure if your browser supports this, please ask below. You should not have to modify any settings, or make any changes at all in order for this to work. Q. How come everyone doesnt do this? A. Most people do not know of its ability, and are not educated on its' use. Q. Will this hurt my web server? A. If your server is properly maintained, there should not be any issues at all. There is a slight increase in processor usage, but with the amount of banwidth being saved, this is a small price to pay. Overview - How to check if this will work on your website? - How to implement it into my site (two options) - How to test the compression results Part 1) How to check if this will work on your website? We first must find out if this will work on your server. This is done by finding out if the zlib module is installed. Either ask your host, or do the following: 1.1 - Create a file named phpinfo.php with the follow code: <?php
phpinfo();
?> 1.2 - Open the file on your sever (suggestion: hit Control+F and enter the text zlib to search for the table), you will be looking for a table that contains information similar to this: quote:
ZLib support: enabled Compiled Version: 1.1.4 Linked Version: 1.1.4 1.3 - If this is shown on the page, you can continue below. If this is not installed, contact your host and ask them to install the module. You can link them to this thread, or tell them the zlib module needs to be installed. Part 2) How to implement it into my site (two ways) You can use code at the beginning of each PHP page, or use .htaccess. ---------------------------------------------------------------------------------------- Option 1) Adding the correct code to each .php page ---------------------------------------------------------------------------------------- 2.1 - The best option is to place specific code at the beginning of each .php page. You can activate the compression by the following code: <?php
ob_start( 'ob_gzhandler' );
?> Your page should look something like this: <?php
ob_start( 'ob_gzhandler' );
?>
<html>
<head>
</head>
<body>
<p>This web page is now COMPRESSED!</p>
</body>
</html> 2.2 - Save your page and continue with Par 3 to test the compression. ---------------------------------------------------------------------------------------- Option 2) Using .htaccess to compress your pages ---------------------------------------------------------------------------------------- 2.3 - The other method is easier to use, and only requires editing of a single file. Begin by logging into your hosting account and going to a file manager type section (details on how to do this will be given by your host- if they are unaware of what you want to do, ask them this: "How do I create and edit a .htaccess file?") 2.4 - Open your .htaccess file, if you do not have one to open, simply create one by naming a file .htaccess. You must do this from your control panel, as it usually does not work if you create the file from your computer, and upload it like that. 2.5 - At the very top of your .htaccess file (if you use FrontPage Serer Extensions, there will be info regarding that inside this file, do not delete or edit it, but simple place your cursor before this line, and hit return to make a new line). You need to add this code: php_flag zlib.output_compression On 2.6 - Save your .htaccess file. 2.7 - Visit your .php pages and make sure no errors exists. Note: If you are running software that already uses this method, an error will be created when you are trying to use .htaccess on pages that already are compressed. You may not run both methods above. Part 3) How to test the compression results There are a few websites that will allow you to rate the level of compression. One that I have used in the past is PipeBoost. This will tell you how much you are saving by using the information in Step 2. Also note that both methods above will produce the same end result. Information and pictures are posted at PHP Page Compression
< Message edited by BobbyDouglas -- 5/3/2005 19:38:55 >
_____________________________
Arizona Web Design - Mr Bobs Web Design in Arizona The Arizona Web Hosting Challenge
|
|
|
|
anderskorte
Posts: 545 Joined: 2/20/2005 From: Finland Status: offline
|
RE: Compress your pages! (Average up to 80%) - 5/2/2005 14:18:11
Hey that's pretty hot. Part 1 is trivial, probably all Linux boxes have zlib installed, it's a must. But how does it work in practice...? It sends it compressed to the browser, but how come the browser knows to decompress it? Since when has IE done gunzip? I get kind of lost halfway reading that.
|
|
|
|
BobbyDouglas
Posts: 5479 Joined: 5/15/2003 From: Arizona Status: offline
|
RE: Compress your pages! (Average up to 80%) - 5/2/2005 15:27:45
Yay! Someone replied. quote:
Part 1 is trivial, probably all Linux boxes have zlib installed, it's a must. - Most have it installed, but I believe the version needs to be .4 or higher. I haven't tested on previous versions of zlib, just because I don't have a test box. quote:
It sends it compressed to the browser, but how come the browser knows to decompress it? Since when has IE done gunzip? I get kind of lost halfway reading that. - It is a standard feature for any browser. Any browser that doesn't include it, isn't a brower I know about! Mozilla, IE, Opera, etc... all support this. I will see if I can clear it up a bit. Anything else that you didn't quite understand?
_____________________________
Arizona Web Design - Mr Bobs Web Design in Arizona The Arizona Web Hosting Challenge
|
|
|
|
BobbyDouglas
Posts: 5479 Joined: 5/15/2003 From: Arizona Status: offline
|
RE: Compress your pages! (Average up to 80%) - 5/2/2005 16:16:11
Right, it only sends the compressed version when it can to the browser....
_____________________________
Arizona Web Design - Mr Bobs Web Design in Arizona The Arizona Web Hosting Challenge
|
|
|
|
BobbyDouglas
Posts: 5479 Joined: 5/15/2003 From: Arizona Status: offline
|
RE: Compress your pages! (Average up to 80%) - 5/2/2005 21:37:23
I talked to one of my sys admins about it, he said that the zlib creates the file on the fly, and that mmcache is what stores the compressed files inside the /tmp folder. I don't think he is 100% sure though. He also mentioned that zlib always sends out the compressed file, instead of the normal file. Like I said, not sure if the above statement is accurate, but it made me think about how it works. Spooky, can you verify what I said above it correct/incorrect? It would be really interesting to find out for sure what it does.
_____________________________
Arizona Web Design - Mr Bobs Web Design in Arizona The Arizona Web Hosting Challenge
|
|
|
|
BobbyDouglas
Posts: 5479 Joined: 5/15/2003 From: Arizona Status: offline
|
RE: Compress your pages! (Average up to 80%) - 5/3/2005 1:07:12
Ah, but you were right. It basically just sends out the one the browser requests. At least that's what I gather from the article. Either way, it is FAST!!!!
_____________________________
Arizona Web Design - Mr Bobs Web Design in Arizona The Arizona Web Hosting Challenge
|
|
|
|
BobbyDouglas
Posts: 5479 Joined: 5/15/2003 From: Arizona Status: offline
|
RE: Compress your pages! (Average up to 80%) - 5/3/2005 11:57:52
quote:
An example, when running httpzip through our server here, pages that weighed in previously at 60-70k pure html are reduced to 10-20k - But there are not duplicates of files, right? Meaning they are not stored in a temp dir until they are requested. quote:
However, compression will give you faster easier savings in page size than css and thrifty coding will ever give you. - I took a site the other day, made it in xhtml/css (not 100% great coding, but still good enough), then put on the zlib, and the page loads sooooooooo fast now. Mix this up with a speedy server in One Whilshire, and you have yourself a screamin fast page. quote:
Before or after the Doctype? - It goes before EVERYTHING. So before the Doctype too. If your page is already php, then you can simply add ob_start( 'ob_gzhandler' ); to the code. But you can still use the exact code posted in my first post, and it will work. quote:
And those not reasons for not are? - It requires a little more CPU usage, if you are on a VPS, it might not be a good idea to run a forum with compression on, if the forum gets high traffic. VPS are already slow enough with high traffic forums. That and the fact it requires a specific zlib module to be installed, are about the only reason one wouldn't use it.
_____________________________
Arizona Web Design - Mr Bobs Web Design in Arizona The Arizona Web Hosting Challenge
|
|
|
|
BobbyDouglas
Posts: 5479 Joined: 5/15/2003 From: Arizona Status: offline
|
RE: Compress your pages! (Average up to 80%) - 5/3/2005 19:27:48
Very nice find Spooky. I will have to add that to the first post. quote:
any ideas as to whether combining compression features is beneficial or will it cause problems with IIS 6 caching? or does it cache the compressed pages as well? - I know that combinations are used on Unix/Linux without problems (assuming you are configuring it correctly). mmcache and the zlib can really speed up forums. I noticed a forum that just started to use mmcache, I can't believe how fast it is. Spooky, if you notice anything really misleading in the 1st post, feel free to edit it.
< Message edited by BobbyDouglas -- 5/3/2005 19:42:53 >
_____________________________
Arizona Web Design - Mr Bobs Web Design in Arizona The Arizona Web Hosting Challenge
|
|
|
|
anderskorte
Posts: 545 Joined: 2/20/2005 From: Finland Status: offline
|
RE: Compress your pages! (Average up to 80%) - 5/4/2005 12:54:11
And also this wonderful method was brought to you by the wonderful world of Unix. Gosh, you just gotta love that system!
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|