50+ PHP optimisation tips revisited

Posted on Friday, May 20, 2011 @ 01:13:35 UTC in PHP
by Raven

Southern writes:  
Enjoy!

1. echo is faster than print.
2. Wrap your string in single quotes (') instead of double quotes (") is faster because PHP searches for variables inside "" and not in '', use this when you're not using variables you need evaluating in your string.
3. Use sprintf instead of variables contained in double quotes, it's about 10x faster.
4. Use echo's multiple parameters (or stacked) instead of string concatenation.
5. Use pre-calculations, set the maximum value for your for-loops before and not in the loop. ie: for ($x=0; $x 6. Unset or null your variables to free memory, especially large arrays.
7. Avoid magic like __get, __set, __autoload.
8. Use require() instead of require_once() where possible.
9. Use full paths in includes and requires, less time spent on resolving the OS paths.
10. require() and include() are identical in every way except require halts if the file is missing. Performance wise there is very little difference.


more with citations: hm2k Internet Engineering
 
 
click Related        click Share
 
News ©

Site Info

Last SeenLast Seen
  • vashd1
  • ofigustavo
Server TrafficServer Traffic
  • Total: 482,332,613
  • Today: 16,815
Server InfoServer Info
  • Apr 19, 2024
  • 11:04 am UTC