There is a post at http://code.google.com/speed/articles/optimizing-php.html by one of Google’s webmasters giving out several tips on how to optimize PHP scripts. Most of it is complete baloney and has been debunked by Gwynne Raskind at http://groups.google.com/group/make-the-web-faster/browse_thread/thread/ddfbe82dd80408cc. What some people will do in the name of optimizing code is absolutely ridiculous. At most they will save a thousandth of a second after putting in 2 days of effort. Here is the proof : Should you optimize PHP? and Readfile vs Include
Both these articles were written quite a few years ago and Interestingly I have received a handful of hate mail from people who spend all their time optimizing code!
If you want your code to execute fast, design a good algorithm or better still look one up in a book. There is no substitute for it. If your app is connected to a database make sure it’s properly designed. If you are retrieving data from a remote server use a cache. All this applies not just to PHP but to any language on any platform.




seriously! some people just can’t get it off their heads. they want to optimize optimize and optimize! some time back my senior was the same. he would have me write “not OO code” because he thought optimization(no setters/getters, use global fields!, less classes, methods..etc) is better than all the benefits of OO. after months of arguing and stuff. he is much better now.
It’a amazing how such morons end up as team leaders – probably because they speak at a level that CEO and directors can understand.
Hahaha, this crap people post never ceases to amaze me.
The best part is the echo vs. print stuff was axed in deference to people noticing
If it’s not in a loop or not recursive, it’s probably not worth looking at.
A few things I’ve also noticed:
Using references in PHP can actually slow things down. Even I make this mistake because I’m used to compiled languages that actually do what they’re told. I’m not sure with respect to “quasi-return by reference” vs. return. However, if it doesn’t need to be a reference because you’re not actually modifying it, *do not use reference passing.* Doing so actually slows things down. Why? PHP won’t copy it anyway if you don’t modify it, so you’re actually making it track/do more. I didn’t believe it at first … but it makes sense.
Also. ” vs. ‘
Anyone who has looked at the PHP lexer knows that the interpolated variables are pulled out by the lexer itself. Using a single quoted string vs. a double quoted string without variables will only speed things up to the extent that the lexer does not have to check for a variable. This will not be measurable.
I don’t know why, but deep recursion may be a problem for PHP sometimes. On the other hand, the function I’m referring to is only anecdotal as was rewritten a far less stupid way
I think what bothers me most about php.net is seeing meaningless profiling/tests of things that don’t matter.
Look at loops. Look at a Donald Knuth book. Seriously, no matter how much you optimize a bubblesort, it’s still a bubblesort.
Consider this a love letter to cancel out the hate mail
thank you for the love letter