Website bandwidth usage and PHP optimization

Thursday 3rd May 2007

Website bandwidth usage and PHP optimization

Though the traffic on my blog has steadily increased, it is nothing (yet) that would warrant the need to optimize the site for better bandwidth usage. However, the hits on my proxy site have jumped up quite dramatically over the last couple of days.

There isn't much I can do about such a site since there is very little content that is loaded from the server itself. However, both the traffic and the resource utilization (namely CPU) are starting to get hammered. And I'm looking at whatever small optimizations that can be done before I have to move it to a more powerful server.

Though the Apache web server isn't the real bottleneck and already quite optimized, I have disabled fancy directory listings (all those AddIcon lines) as well as extra Apache modules, such as mod_proxy. That'll be all for Apache (for now at least). I remember using the bare, optimized config file that is shipped with the Apache source and employs some of the same techniques. Will check that again if Apache ever requires more fine tuning.

For PHP optimization, I found a number of resources, though the 12 PHP optimization tricks page is probably the best and most famous one. Not all of these tips were applicable in my case, but I managed to cook up a few myself. I have taken out a number of the if statements from the PHP code since most of them weren't required anyway and am looking at what else can be changed.

Logging has also been controlled to minimize disk i/o. I was a bit frustrated that there doesn't seem to be any option in Apache to disable logging for a particular virtual host. Your options are either to log the hit to /dev/null or set a condition using SetEnvIf. Here's how I did it:

SetEnvIf Request_URI "^/index\.php?" dontlog
CustomLog <path_to_logs>/www-access_log combined env=!dontlog
CustomLog <path_to_logs>/www-referer_log referer env=!dontlog

What this does is to only log requests that don't start with /index.php? and this has drastically reduced the size of my logs.

For bandwidth consumption, here is a nice page that I happened to find on reducing a website's bandwidth usage which could come in handy if you're running your own blog or website. Carry on webmastering.

20:00pm


On 5th May 2007, at 12:18pm PKT, Atif said:

Interesting facts.

On 9th May 2007, at 16:38pm PKT, Web Proxy said:

Hi, I couldnt find a contact button

Please re-add the links you removed from http://webpxy.com for both the designer and the proxy integrators work into the design

You are infringing copyright