November 11th, 2007  
-HAL-
Administrator
 

Posts: 860
Country: Norway
Microchips: 2,732
Gadgets
Ubuntu Tux redhat Windows
Commodore Intel NVIDIA

Post - 40 PHP Optimization Tips


Just came across this really nice article.
I knew several of them, but there's a few new interesting ones I'll test on my next PHP programming project..
  1. If a method can be static, declare it static. Speed improvement is by a factor of 4.
  2. echo is faster than print.
  3. Use echo's multiple parameters instead of string concatenation.
  4. Set the maxvalue for your for-loops before and not in the loop.
  5. Unset your variables to free memory, especially large arrays.
  6. Avoid magic like __get, __set, __autoload
  7. require_once() is expensive
  8. Use full paths in includes and requires, less time spent on resolving the OS paths.
  9. If you need to find out the time when the script started executing, $_SERVER[’REQUEST_TIME’] is preferred to time()
  10. See if you can use strncasecmp, strpbrk and stripos instead of regex
More here:
http://reinholdweber.com/?p=3