19 thoughts on “PHP performance tips”

  1. @benjarriola Actually, in PHP, a while loop will run faster. But the gain is not significant at all(something such as 0.001 seconds for 100000 iterations…), so it's not worth changing all your for loops for while in your scripts

  2. @realluinnar Wrong. At that point, you're going into load-balancing, DB tuning and caching of all sorts; and if that fails, improve your algorithms. Do you think it makes a difference if a server is 99% or 98% loaded?

  3. It should also be added that, benchmarking to the millisecond difference is actually EXTREMELY hard to do – background processes on a server, anything can cause these so-called 'benchmarks' to be off. Iterating a thousand times isn't a real benchmark.

  4. FYI: The official php developers have refuted these tips as false. Single vs. Double quotes is an age old argument and they're a wash – if not doubles are faster.

    Echo vs. Print is another one, his reason for doing so is a little off – if anything print -could- be slower because it returns 1, echo doesn't bother to return.

  5. These were the most insignificant performance tips ever to exist. Your benchmark towards the end was laughable. I'll bet you $100 you can't find a noticeable performance gain using these.

    Proper performance tips include "caching database results", "using an op-code cache (APC)", "re-factoring loops", etc.

    Actually, anything that what wasn't on the video would of been more useful.

  6. It must be a joke.

    Does Google actually use… PHP?

    And the first example is priceless. "Imagine if a malicious user had inserted 512Kb worth of characters". Yeah, right, but the real issue is an obvious cross-scripting vulnerability. What a wonderful example.
    And as pointed out by Noobenstein, PHP does COW for variables.
    This is nothing but misinformation. It must be a joke, I can't believe this video has been made by Google.
    Real PHP performance tip: use PHP-FPM.

  7. I'd rather use double quotes for long strings that need lots of variables because it makes the code more readable.

    I guess these tips only apply if you're expecting a million hits per day or something. Otherwise, it's not worth the hassle.

Leave a Reply

Your email address will not be published. Required fields are marked *