Home About Contact

50+ PHP optimisation tips

Posted by phorner On July 15, 2009

PHPFor those of you who program in PHP, this list of PHP optimisation tips is invaluable. It’s an accumulation of accurate tips and provides references and citations for each and every one.

Some examples:

  1. Use sprintf instead of variables contained in double quotes, it’s about 10x faster.
  2. Use pre-calculations, set the maximum value for your for-loops before and not in the loop. ie: for ($x=0; $x < count($array); $x), this calls the count() function each time, use $max=count($array) instead before the for-loop starts.
  3. “else if” statements are faster than select statements aka case/switch.
  4. ++$i is faster than $ i++, so use pre-increment where possible.

… and many, many others.

I’ll definitely be applying all of these optimisations to my code in the future.

For more information: 50+ PHP optimisation tips revisited

  • Share/Bookmark

25 Responses to “50+ PHP optimisation tips”

  1. Andrew Toan says:

    Thanks, nice collection

  2. Someonw says:

    I strongly disagree with number 34. Use binds and and let the database do the work of escaping your SQL statement.

  3. Thanks for the post it was very informative.

  4. how to get ringtones

  5. This is a really good article. I enjoyed reading it. I gained a lot of information reading your post. I really loved it.

  6. I was’nt sure I would like this site since it was about 50+ PHP optimisation tips | Weblenium but I was wrong and thought it was cool and found it on Bing . Thanks and I’ll be back as you update.

  7. Amazing Dude, this is very nice information, appreciated.

  8. I take this also to disclose the site of a friend in Brazil if they need web hosting, is http://www.planetaservidor.com.br

  9. Abi says:

    SomeThat’s great info tx. Anybody know about a reliable search engine marketing firm who will not do a sub-standard job?? I’ve got soooooo much SEM work to do and no where near enough time….. Need to pay someone to help!

  10. Let the debate begin!

  11. backlinks says:

    Great post. Will you please write more about this subject.

  12. I like the layout of your blog and Im going to do the same for mine. Do you have any tips? Please PM ME.

  13. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.

  14. Keep it up guy. I really enjoy the stuff here. Very well informative and educational.

  15. Frank Gaut says:

    great info ! i just know that .. Thanks ..

  16. Hmm .. You have a good site and this post is awesome .. I’ll come back again and subscribe your RSS for sure :)

  17. Good info ! i just know that .. Thanks ..

  18. Hi .. i see you have a great post ! i hope you could make another one like this .. keep posting then :)

  19. Hi .. i see you have a great post ! i hope you could make another one like this .. keep posting then :)

  20. Robby Valent says:

    Hey, this is my first comment on ur site. I’ve been reading it for a while in my RSS reader but haven’t commented before. :) Anyways, thanks for the post.

  21. I enjoy reading it. I need to see more on this topic.. Thanks for writing this nice info.. Anyway, I’m going to subscribe to your rss feed and I hope you post again soon.

  22. Thank you very much for the information provided! I was researching for this info for a long time, but I was not able to find a reliable source.

  23. Great article}! i know you are the best writer. your post is well written and i think i will bookmark this site and share to my friend .. have a nice day :)

  24. Really great entry to hang on.. I am truly impressed with this article. Looking forward for future posts.

Leave a Reply