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