Hull Design Online

PHP Optimise Pages

Page 1 | Page 2

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.

<?php phpinfo(); ?>

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.

<?php ob_start( 'ob_gzhandler' ); ?>
 

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.

<?php ob_end_flush(); ?>
 

Move on to the next page to find out how to automatically enable this for all files on the server using .htaccess.

Page 1 | Page 2

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.

 

 

Hull Design Online YouTube Channel Hull Design Online RSS

Bookmark and Share

Latest

Smoke Scene Design
Modern Bokeh Effect Realistic Snow Photoshop Layout
Create Newspaper Headlines Halloween Poster - Part 2 of 2 Halloween Poster - Part 1 of 2
Halloween Text Time Greeting Sticky Tape
Business Card Design Draw Lined Paper Amazing 3D Text
Stunning Typography Create Realistic Reflections Widescreen Border
Indented Text Effect Advanced Shadows Text Styling Tutorial
Website Status Checker Load Time Optimise Pages
Shorthand CSS Optimise Your Windows System Manage Your Passwords Safely and Securely