PHP Code Optimization
Customer Service, PHP, Web Design April 2nd. 2008, 5:17pmIn the past ten years computers have become so powerful that small performance tweaks and good coding standards and practices are overlooked. The reason for this is because coders have very little reason to care about coding standards and practices these days. It used to be that if you wrote sloppy code or didn’t take the time to optimize your code, you saw a drastic decrease in the performance of your program or script. Now that computers are as powerful as they are, even sloppy unoptimized code performs at such a high speed the loss of performance is barely noticeable.
At least that is what someone who writes code like that will tell you. At Storm Code we follow a best practices formula for writing optimized, performance driven code. If you run a small website with just a few scripts that are not often used, then you would notice very little difference (if any) between optimized code and unoptimized code. However, as your website grows in users and complexity the performance gap between unoptimized and optimized code grows larger quickly.
Several performance enhancing techniques can be used while coding. One of these examples is the use of single quotes instead of double quotes. An Example String using single quotes and double quotes in PHP:
echo ‘Hello World!’; // Single Quotes
echo “Hello World!”; // Double Quotes
In PHP, when using double quotes the parser looks for variables and formating information inside the String while using single quotes tells the parser not to look for variables and formatting information. Many coders use double quotes all the time for simplicity however this can cause a decrease in performance especially in large scripts that output a lot of information. Double quotes should only be used when formatting or variable matching is needed. This is one of many performance increasing best practices for PHP that Storm Code employs.
The main thing to remember is that doing something right the first time will save you having to redo it again down the road. Just because a website does not have a large user base or complex functionality right now, does not mean that it will not in the future and keeping performance and optimization in mind when coding, or hiring coders will not only save you money, but also headaches.
One Response to “PHP Code Optimization”
Leave a Reply
You must be logged in to post a comment.
February 3rd, 2009 at 12:26 pm
PHP Code Optimization | Storm Code…
In the past ten years computers have become so powerful that small performance tweaks and good coding standards and practices are overlooked….