50+ PHP optimisation tips revisited

Posted on Friday, May 20, 2011 @ 02:13:35 PDT 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 v2.2.2

Last SeenLast Seen
Server TrafficServer Traffic
  • Total: 343,817,976
  • Today: 52,099
Server InfoServer Info
  • Dec 10, 2017
  • 08:09 pm PST
 
 

Daily Inspiration