PDA

View Full Version : PHP Performance and Object-Oriented



Miga
18 Jul 2010, 10:36 PM
Hello

I am looking for a way to increase the speed of my php code.
I have built a page with contact form and newsletter form that would validate with php/jquery.
If newsletter form is entered, it will generate confirmation code, insert into db, and then email it. It does not actually send emails to all the members. It just sends the first confirm email to the new member.

If contact form is filled out, it just sends an email.


p-code would be like this...




init vars

if contact form is submitted {
validate the form
if no errors found {
send email
}
} else if newsletter form is submitted{
validate the form
if no errors found {
generate confirm code
insert confirm code and email into db
send email
}

////HTML START///

if var newsletterSent is set {
echo thank you, email successfully sent
}
re-init the form vars

HTML CONTACT FORM

if var newsletterSent is set {
echo confirm code is sent to your email, thank you
}
re-init the form vars

HTML NEWSLETTER FORM

HTML END




My problem is that the page takes like 10 seconds to load. This code is built in procedural way. If I make this object-oriented, would that improve it?

Also, I read about eaccelerator. Is it worth giving a shot?



Thank you

TheMichael
20 Jul 2010, 11:10 PM
Validation and a simple database entry should NOT take 10 seconds to load (unless I misunderstood your post). You are probably bottle-necking on something. You need to find that bottle neck and get rid of it. Even difficult and tedious tasks usually don't take more than a second or two to execute in PHP. Find out exactly WHICH part of the process is creating the extra load time.

OOP may under certain circumstances improve load time, but in most cases it is not a notable difference in such small applications. OOP is designed to make future revisions and easier, and structure cleaner.

Let me know if you have any questions.