Optimizations in PHP

Optimizations in PHP

Google’s article on PHP in connection with “Let’s make the web faster” has taken a beating in the last few days. I also consider many of the tips to be nonsense or a drop in the ocean.

Basically, I think it’s a good idea to start a profiler first before doing (supposed) optimizations. I also firmly believe in “Premature optimization is the root of all evil”. Often, small performance gains mean that clarity and expandability are forfeited.

Here is a little performance tip from me: For AND operations, always pull the condition, which is usually false and / or the easiest to determine, to the front, because most interpreters and PHP no longer evaluate the other conditions as soon as one of the conditions false results in:

if ($countrycode=="AT" && complexCalculation()) ...

If Austria is not meant at the time of the query, the complexCalculation () is not called at all. If the conditions were reversed, complexCalculation () would always be carried out, even if the $ countrycode does not match and the result of complexCalculation () is actually irrelevant.