Home About Contact

50+ PHP optimisation tips

Posted by phorner On July 15, 2009

PHPFor those of you who program in PHP, this list of PHP optimisation tips is invaluable. It’s an accumulation of accurate tips and provides references and citations for each and every one.

Some examples:

  1. Use sprintf instead of variables contained in double quotes, it’s about 10x faster.
  2. Use pre-calculations, set the maximum value for your for-loops before and not in the loop. ie: for ($x=0; $x < count($array); $x), this calls the count() function each time, use $max=count($array) instead before the for-loop starts.
  3. “else if” statements are faster than select statements aka case/switch.
  4. ++$i is faster than $ i++, so use pre-increment where possible.

… and many, many others.

I’ll definitely be applying all of these optimisations to my code in the future.

For more information: 50+ PHP optimisation tips revisited

  • Share/Bookmark

About

Posted by admin On March 30, 2009

Hi my name is Peter Horner. I have been programming now for the last 25 years (started with BASIC and worked my way up). I have a Bachelor of Science (Comp. Sci) from Macquarie University, Sydney, Australia. My first job was using Macromedia Authorware to create CDROM based Human Resource Training. We then went on to use Flash to deliver the content over the web. After 9 years with this company, I moved on and became a Freelance developer, working on projects for Vodafone, St George Bank and State Rail (NSW).

Since moving to Germany, I have continued to work for companies in Australia developing websites, Flash games, webcam apps using Flash Media Server and many other things.

My skills include: C/C++, Javascript, Java, PHP, mySQL, HTML, CSS.

My main hobby is golf. My wife and I play quite regularly and enjoy playing all around the world (when time permits). We have started a new website called Golf Home Exchange to help other golfers around the world spend less on accommodation and more on golf.