prosperwebsolutions.co.uk
17a Bennington Street
Cheltenham, GL50 4ED
T 01242 808413 | online enquiry form

Blog

<November 2008>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

Top Stories

Archives

 Monday, November 03, 2008

Top 10 PHP Performance Tips

Right I will be quick and straight to the point, after developing a massive website that was purely written in PHP and had MySQL back end this is what we have discovered.

  1. Don’t Use PHP Magic, __get , __set any of this, forget about it, don’t even bother.
  2. Open 1 and I repeat only 1 MySQL connection per page request, and make it global, PHP closes the connection for you at the end however it is a good practice to close it at the end as well.
  3. Don’t use include_once, just use include
  4. If you have written any kind of framework for your website, for development break them in to different files, however when it comes to production just put everything in to one file. Less includes the better.
  5. Don’t use call_user_func unless you really have as it is very expensive
  6. Don’t use eval unless you have to as once again it is very expensive
  7. When call MySQL try to do batch inserts where you can using ; delimiter.
  8. Research APC (Alternative PHP Cache), ensure you understand it, and use it across the site and cache anything you can, with in reason. It is one of the things that facebook has contributed to the community, and it has great support from people like Rasmus.
  9. Try and avoid loops and complicated functions. Seriously write simple code, you can go crazy with loops when you are using something for hard core processing for website management but when it comes to the general user everything must be light and scalable.
  10. If one the most common things that people always say use ‘ instead of “ so write  ‘error’.$something.’ Occurred’ , instead of “error $something occurred”, this is obvious one however I still prefer the other way as you can write it like this “ error {$something} has occurred” it just simply looks good, I know it is en-efficient but I don’t care.

These are just minor few things, but APC is the the best thing you can do for performance improvement, yes you can write DLL files that make things quicker, but being realistic you will not need to do that unless you doing mass user or content management. In which case you can write C# or C++ application

Monday, November 03, 2008 11:31:17 PM (GMT Standard Time, UTC+00:00)
^ Skip To The Top