PHP "speed coding" tips

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi everyone

I wondered what if any methods people here use to speed up their PHP  
code (ie. speed at which you produce your code).

Things like 'code templates', 'base objects' for this and that?

I thought it would be interesting to find out if I'm missing out any  
anything cool that could aid in speeding up development.


Re: PHP "speed coding" tips

Quoted text here. Click to load it

Well, I don't think it's really something that matters. Like people
here say "Measure three times, cut only once", in programming it's the
same thing. It's better that you rethink your ideas in advance so you
don't have to write double code, to change your mind throw away last
two days and start solving the problem in different direction, to
organize the solution in such way that you can easily extend it later

The only "mechanic" thing you could do to make your coding faster
would be learning touch-typing, since watching at the keyboard
distracts you way too much from your code.


Re: PHP "speed coding" tips

Tyno Gendo wrote:

Quoted text here. Click to load it


speeding up the executiontime of code is of course a different matter than  
speeding up your developmenttime.

Speed up execution: A lot can be said about this. I just want to say that  
most scripts that that are slow use stupid/repetitive databasequeries.
Solution: Learn better SQL and fix it. :-)

Speed up developmenttime: This is a difficult matter and very personal to  
most programmers I suspect.
My opinion: Whenever you start with a project that is modarate complex: be  
sure you design your database in advance, before coding PHP.
A good databasedesign is the start. Understand concepts like normalization,  
foreign keys, indexes, etc.
In the real world, you always must change your database during development.  
The better your original design, the less pain.

As templates and third party objects go: I never use them, only PEAR  
packages, and 'famous/proven' third party code like ADODB (not the VB  
thing) and htmlmailers.

I have trouble folding my mind into other people's 'programming flowcharts'  
or patterns, so I tend to write everything myself. That way I am sure I  
know what I am doing.

If that is wise, I cannot say.  
It saves time when you reuse other people's code.  
It costs tremendously when the code fails and you can start debugging other  
people's code.
In the end it is a matter of trust. Do I trust that X or Y wrote good code  
that I dare to use in my software I develop?

I have (and many more coders too) a lib with functions I wrote and reuse in  
different projects. I know how they work, and what they can or cannot do.
That saves time too.

If you are relatively new to PHP (I don't know your expertice), my advise  
would be to first learn everything yourself, learn pitfalls, and write your  
own code without templates/patterns/thirdparty addons/etc.
When you are comfortable with your skills, you can judge what packages you  
trust enough to incorporate into your software.

It won't hurt to ask in here what people think about a certain framework or  
package. If you receive a lot of complaints, don't use it of course! ;-)

Just my 2 cent.

Erwin Moller

Re: PHP "speed coding" tips

On May 8, 7:57 am, Erwin Moller
Quoted text here. Click to load it

Hi Erwin, I am a new PHP programmer too - I used to do plain HTML. My
answer might sound a bit pathetic, but it sure works: I rely on IDE,
but it must be a good one. I got NuSphere PhpED - they have what you
are asking for, code templates, code completion - + debugger, I think
this is one most important thing. I understand that this is different
from what you are talking about - I am not relying on any PHP
framework, but it sure serves me well, so I figure I'd share it with
out. Please forgive me if I am wasting your time :-)

Re: PHP "speed coding" tips

Quoted text here. Click to load it

... I can hear Leia now... "The faster you code, the more bugs will
slip through your fingers."

Some of the frameworks can add some speed once you get the hang of
them. Check out CakePHP (it's similar to Ruby on Rails):

A lot of speed is inherent in the design decisions you make, which
will come with experience.


Re: PHP "speed coding" tips

Tyno Gendo wrote:
Quoted text here. Click to load it
Hi Gendo,

Better then producing more code per hour is to do more with less code:  
the result is easier to change and it will probably contain less bugs  
too. Since 1996 i have built 3 generations of frameworks to accomplish  
this, nowadays i need very little code to build an application. Last  
project i measured a productivity of between 200 and 900 times my  
productivity back in 1996*. The framework is free to download and use,  
but requires a good understanding of OOP, and even then it will take  
some time before you get up to speed. It tends to replace coding with  
exploring and thinking. Not everybody likes that.


Henk Verhoeven,

* By then apps where GUI based, in Smalltalk, using a screen painter  
tool and an Object to Relational DB Mapping library.

Re: PHP "speed coding" tips

Quoted text here. Click to load it

It has gone way beyond that; these days, there are full-blown rapid
development frameworks...  Unfortnately, applications you produce
using those tends to be slow.

Quoted text here. Click to load it

Cool is a subjective notion.


Re: PHP "speed coding" tips

Kimmo Laine wrote:
Quoted text here. Click to load it

Unless next_page.php generates PHP, the script with this include will
only get HTML.

Quoted text here. Click to load it


    if (isset($_GET['foo'])) {
      echo '<?php echo $_GET[\'foo\']; ?>';
    } else {
      echo '<?php echo \'Not available\'; ?>';

File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

Re: PHP "speed coding" tips

Quoted text here. Click to load it

First and foremost, a good IDE will save you gobs of time simply by
having autocompletion.  (It'll also prevent accidental typos in
variable names).

You can get into code templates and whatnot, but sometimes I feel like
the time it takes to make the template ends up costing you more time
that it saves.  I have a few code templates set up in Zend studio to
pop in some debug code that I delete once I find the problem, and that
is helpful, but I don't typically use code templates for production
code.  My personal rule: if I have to rewrite the same logic 3 times,
then it's common enough that it belongs in a class or function, not in
a template.

Re: PHP "speed coding" tips

Moot wrote:
Quoted text here. Click to load it

I HATE auto-completion!  I'm a touch typist, and often am not looking at  
my screen when I'm typing - especially code (i.e. referring to notes).  
And it "help" just gets in my way :-).

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: PHP "speed coding" tips

Well when it comes to speeding up the development process people will
generally say that it's better to take your time and get it right the
first time.
This is true, but once you have succeeded in perfecting a peice of
code (such as connecting to a database) - you should save that code
and turn it into a snippet.

I use DreamWeaver 8, this program has built in snippet manager so if I
write a login system that I think should work for just about anyone, I
can save the code and depending on how you write it - you can simply
set variables at the top of the code.

For example, let's say I have a long login script with many options -
my options could be something like the following:

$userName = 1; // Ask for a username.
$userPass = 1; // Ask for a password.
$randImg = 0; // Don't generate random image verifcation.
$storeSession = 1; // Keep a session going for this login.
$storeCookie = 0; // Don't store a cookie for this login.
$rememberUser = 0; // Don't remember this user.
$formAction = "main.php"' // Where this form will be submitted.

This may be a little crude but this is the general concept. You have a
module that works - and all it needs are simple flags, and after this
is done you can generate an entire user management system in minutes.

I have written a script or two that I simply setup the INI file and
then run the script and it creates directories and files and sets up a
standard 5 page website with a content management system.

These are just some ideas.

Quoted text here. Click to load it

Re: PHP "speed coding" tips

Quoted text here. Click to load it

I found looking at how you work is very helpful. Looking at how you
design, how you turn it into code, where you need to improve, how you
can decrease debuging times by not injecting bugs etc. I landed on the
PSP process which requires that you log and analyse in detail how you
work. Its very involved process and its not for everyone, but I found
it useful as a guide.

There are other methodologies for this out there, but its really just
a case where you just sit back and keep an eye on how you work and
identify where you need improving then do so.

Re: PHP "speed coding" tips

Quoted text here. Click to load it

Sometimes, using a (html) templating system (there are many, is the quintessence) can speed up your
development. Such things can also slow you down if used in the wrong
situation or in the wrong way. It might also keep you focused on the
PHP code when you are writing logic, and the browser code when you are
working on that. When I started using templating engines, I found that
I work more quickly. This can, in turn, increase page load time, but
alternatives to Smarty are often faster and worth the extra processing

This is useless when writing a cron job, an AJAX serving script, a
reusable class, and a lot of other common things, but there are
probably more cases in which it can be used (not all when it /should/
be used).

-Mike PII

Site Timeline