PHP Optimise Pages
So you've read our Load Time tutorial, and now you want to optimise your pages, right? You won't believe how easy this is. Really. It's just one line of code. That's right, just one.
Before you get too excited though, you need to make sure your server or hosting provider supports it.
This is easily checked by running the phpinfo(); function.
This method can't be used with UTF8 character encoding declared at the start of the script. Try the .htaccess method instead.
Do a search for the ZLib Support section. Is it enabled? Yes? Great! No? Contact your hosting provider, or server administrator. If you are the server administrator, recompile PHP with:
--with-zlib
We are going to use ob_start();. This function is responsible for holding the output of the script until it's ready to be shown. If you have the ZLib Support enabled, add the following to the top of your PHP script.
As ever, it's always good practice to close or end a function that we started. Therefore, you should place the following at the bottom of your PHP file.
Move on to the next page to find out how to automatically enable this for all files on the server using .htaccess.
This tutorial is up to date as of 24 August 09. While you're here, why not check out more tutorials? You could also subscribe to our RSS Feed, or even check out our Twitter - follow us for the latest updates. For video tutorials, subscribe to our YouTube channel. Feel free to check out our blog for more updates.
