Saturday, 24 November 2012

A small hint to make your PHP site much faster

If you've dug through your code to the best of your abilities, and optimized it as far as you can.  If your site is still slow, there are a few things you can do.  The first is install a byte code cacher like eAccelerator or APC.  Both of them store the compiled version of a PHP file in memory, which saves the time it would take for the server to compile the code.  While this is not a GREAT savings, it can be dramatic.  You can save between 5% and 25% off load times depending on your code.  The downside to this is two fold.  First, you must have root level access to the server to compile in the cacher.  The second problem is that they use memory.  And lots of it!  The average Joomla configuration will consume about 15 megs of ram.  PER APACHE CHILD.  One Apache child can serve one request at a time.  You can see how this will quickly limit the amount of traffic you can receive.  The other alternative it install a page cacher, such as my Joomla component.  By storing generated pages between requests, these programs can cut down page load times by over 90% or more.  Don't forget that you don't want to put a band aid on a broken bone, but if all else fails, these methods do work.

In general:

Match your hardware to your load, NOT to your generation time.  To upgrade to a dual Xeon server because your pages take 4 seconds to load on that Celeron is nothing short of a waste of money.  Poor code will run poorly no matter what hardware you put it on!  Optimize your code so that it loads fast on that Celeron (or shared host for that matter), and upgrade to the dual Xeon when your demand requires it!  You can do a lot with a little bit of processing power.  And don't let a host tell you that you need a dedicated server because your site is using too many resources.

No comments:

Post a Comment