search engine optimization   Programming blog
        SEO        Link Building        Services        Genie Magic        Web Design        Contact Us        SEO Tools
 
   
php code optimization tips, Wednesday, October 29, 2008
   
 

Do you know the ways to optimize your php code. Here we have some tips for you.

  • If a method can be static, declare it as static. It will improve the Speed by a factor of 4.

  • You should use echo as it is faster than print.

  • If you have to concat string, Use echo's multiple parameters.

  • Set the value of how many times it should be iterated before the loop. Do not assign the value in the loop.

  • When a variable is no longer useful, unset those variables which will free memory.

  • Use absolute urls in includes and requires.

  • To get the time of when the script started its execution, you must prefer $_SERVER ['REQUEST_TIME'] than time ()

  • Str_replace is faster than preg_replace

  • It is much better to utilize switch statements than multi if, else if statements.

  • Every time close your database connections when you got all the datas from DB

  • Always use $row ['name'] to get data from DB.Because it is 7 times faster than $row [name]

  • Don't use functions inside of for loop, such as for ($y=1; $y <= main ($arr); $y) the main () function gets called each time.

  • If you declare a global variable and you are not using it in any function will slow down the performance because will check if the global exists or not.

  • Methods should be in derived classes. This will run faster than the method which was defined in the base class.

  • Surrounding your string by single quote (') instead of double quotes (") will be little faster as php looks for variables inside "" but not inside ''.

  • A PHP script will be at least 2-10 times slower than a static HTML page by Apache. So it is better to use lot of static HTML pages with less scripts.

  • You must install a PHP caching product to naturally boost the performance by 25-100% by eliminating compile times. Your PHP scripts will be recompiled each time if the scripts are not cached.

  • Do not use OOP concepts too much because each method and object call consumes a lot of memory.

  • Split methods that has the code you will really re-use too much.Do not split all the functions.

                                Earthlink Netscape Netvouz RawSugar Shadows Sphinn StumbleUpon Yahoo MyWeb

 
   
 

posted by power @ 7:14 AM permanent link   |

Post a Comment

|

 

2 Comments:
  • At January 7, 2009 12:08 PM, Anonymous Darin Boyd said…

    I enjoyed the post. There is so much information about optimization buried in dark corners all over the web. It is good to see a list of "do's" to get kick started. I do have a question though. You wrote "Always use $row ['name'] to get data from DB.Because it is 7 times faster than $row [name]"

    What is the difference between $row ['name'] and $row ['name']? Did you mean to use the numeric index as apposed to the text key?

    Again, thanks for the great post.

     
  • At February 2, 2009 2:42 AM, Anonymous shmeu said…

    He means $row [name] (notice the lack of '') will have to check at least if < name > is not a constant, where $row ['name'] (with '') will evaluate <'name'> as being a string index without other verifications.

     

Home

 

Categories
 

 
Archives
 
Previous posts
 
 
PageRank 10 sites
Search Engine Optimization SEO Blog
Search Engine
Optimization SEO News
SEO Copywriting Blog
Web Design Blog
Link Building Blog
Pay Per Click (PPC) Blog
Programming Blog
Search EngineGenie Blog
Lara's Personnal Blog
Search Engine
Optimization SEO Forum
SEO Comics
Webmaster & Search Events
 
search engine optimization
search engine marketing
SEO consulting
SEO plans
SEO services USA
search engine optimization SEO forum
SEO comics
Webmaster & Search Events
SEO Faqs
link popularity
strategies of link building
link building services
link cost
link request quote
link building blog
search engine genie company
our team
our celebrations
our experience
SEO
why us

web design
web designing services
dynamic website
web design and marketing
simple e-commerce website
complex e-commerce website
search engine friendly site
web design blog
web design
link building
internet marketing
ecommerce implementation
pay per click services
shopping feeds optimization
shopping cart customization
product development
online forms & database integration
programming services
PHP programming services
programming services Java,J2EE
.NET application development programming services
business process outsourcing
offshore outsourcing
Google Products(froogle feeds)
search engine optimization articles
google articles
yahoo articles
miscellenous articles
search engine optimization SEO blog
search engine optimization SEO news
SEO copywriting blog
web design blog
link building blog
pay per click (PPC) blog
programming blog
lara personnal blog
Search Engine Genie Blog
Google Tools
Yahoo Tools
MSN Tools
Comparison Tools
Link Popularity Tools
Search Engines Tools
Site Tools
Keyword tools

contact us
support
our guarantee
events