PHP Optimization to improve performance

| No Comments | No TrackBacks

When coding in PHP in variety ways, some way is simple, some is not. But there must be one better way that can provide better performance.

Here is a list of 63+ best practice to optimize PHP code performances

I learn some from it.


  • echo is faster than print.

  • require_once() is expensive

  • If you need to find out the time when the script started executing, $_SERVER['REQUEST_TIME'] is preferred to time()

  • str_replace is faster than preg_replace, but strtr is faster than str_replace by a factor of 4

  • It's better to use select statements than multi if, else if, statements.

  • Close your database connections when you're done with them

  • $row['id'] is 7 times faster than $row[id]

  • Do not use functions inside of for loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time.

  • When echoing strings it's faster to separate them by comma instead of dot. Note: This only works with echo, which is a function that can take several strings as arguments.

  • Do NOT use SQL wildcard select. eg. SELECT *



Related Articles

No TrackBacks

TrackBack URL: http://www.yinfor.com/mtcgi/mt-t-1102.cgi/2177

Leave a comment

About this Entry

This page contains a single entry by David Yin published on June 6, 2008 4:44 PM.

Tux Paint was the previous entry in this blog.

jQuery UI 1.5 release is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.21-en

Online Tools