A few tips to speed up PHP code

by Rekha 2008-03-15 14:16:04


Here are some few tips to speed up php code.

Tip 1:Using a good editor can really save you time. If you're still stuck on using Notepad to edit your PHP scripts, switch right now.The biggest advantage you get with a proper editor is code highlighting. Code highlighting can help you debug your scripts, or follow code logic.Using a good editor is the ability to do powerful search-and-replace operations. In short, use a good PHP editor, and you will save a very big amount of time.

Tip 2:Most of your PHP scripts will probably do many of the same tasks, such as database functionality (insert, update, select, delete), and have many of the same functions. You could re-write these functions and tasks every time you start a new project, but that seems a bit pointless. Instead, you could use an existing framework or skeleton, and base your new scripts on that.

Tip 3:During the development of a new script, you will probably run across many problems, and you'll have to think of a good solution.The best way is to make everything as simple as possible. Keep everything as short as possible, and if-statements and loops should be never longer than 10-20 lines. If they become longer, first look if you can do it simpler, and if not possible then break it up in blocks, to make it easier to follow.

Tip 4:If you're going to build a CMS for your website, which is actually one of the most common things PHP developers create, then you should first look at existing scripts. There are plenty of great scripts already, and many of them are completely free, often licensed under an open source license.This will save you a significant amount of time, which means you can focus your time on other tasks. Of course in some situations, when you have really specific needs, it won't be possible to use an existing script.

Tip 5:Another great way to speed up development is to properly document your code, especially the complicated parts.If you properly document your code, you will be able to understand it much easier later on, which means you won't have to spend time on figuring out what the code actually does, and can immediately start writing new code. Good documentation can really save you a good deal of time.Each developer has his or her own style, but make sure that other developers can read your code as well. This is especially important when you work in a team.

Tagged in:


You must LOGIN to add comments