Tuning PHP

If you have a switch statement, place the most common cases at the top.

Use single-quotes instead of double-quotes. With double-quotes, PHP engine has to slow down to check for variable interpolation.

Use output buffering to concatenate large number of small strings. The most expensive part of combining strings is memory allocation. Output buffering reduces memory calls by allocating a huge 40K buffer initially (with 10K increments).

(empty($s) && (strlen($s) == 0)) is faster than (strlen($s) == 0) because empty() is a language construct, and strlen is a function.

XDebug has feature for profiling your PHP code.

http://www.linuxjournal.com/article/7213

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License