Some Php Optimization Tips - Webmasters - Nairaland
Nairaland Forum › Science/Technology › Webmasters › Some Php Optimization Tips (552 Views)
| Some Php Optimization Tips by elvis10ten(op): 11:24pm On Dec 12, 2013 |
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. |
| Re: Some Php Optimization Tips by elvis10ten(op): 11:35pm On Dec 12, 2013 |
Do not use functions call inside the conditional part of a loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time. |
| Re: Some Php Optimization Tips by elvis10ten(op): 11:39pm On Dec 12, 2013 |
Pre increment (++$i) is faster than post increment ($i++). You have to know the difference between both tho, else you might end up drinking 5 cards of panadol, because $a = ++$i will not produce the same result with $a = $i++ . |
| Re: Some Php Optimization Tips by elvis10ten(op): 11:42pm On Dec 12, 2013 |
add yours. |
5 Tips For Search Engine Optimization • Does Anyone Know About Search Engine Optimization? • Advertisement Vs Search Engine Optimization • 2 • 3 • 4
Vacancies For Web Developers, UX/UI, Digital And Social Media Managers • Didyouknow You Can Discover Local Events With Facebook’s "Events For You" • Developer Needed To Partner On A Project.