Frameworks, speed, and how fast compared to own-framework

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
dev_php_11
Forum Newbie
Posts: 8
Joined: Tue Feb 02, 2010 11:48 am

Frameworks, speed, and how fast compared to own-framework

Post by dev_php_11 »

I'll make it quick:

1) I want to make the project first and foremost, but I want to be able to use the same code for future applications (think Engine or framework of some sort).

2) I want to make everything scalable, meaning, if I want to write a "submit.php" file, rather than typing in html for an input tag: <input type="submit' name="submit" value="Log in" />

I can just do: submit->process("Log in")

or something of that nature, in case I wanted to add functionality to the submit class, add images, additional processing, etc.

3) I need the site to be able to handle heavy loads. Framework benchmarks (CodeIgnite is the fastest it seems) say that they are often 40+ times slower than procedural PHP. Is this because of OOP design by nature (ie. createInputTag('name', 'value', 'type') with the additional overhead, vs. procedural: <input type="text", etc.... >)?

Does creating OOP projects increase the overhead for speed reasons, and is this why frameworks are slow? Or are frameworks slow because of other reasons?



When I see 40+ times slower than native PHP I think to myself "why not just code per application?". But then I think, "what if I want to change/add something, OOP makes it SO easy".

It seems this tradeoff is causing me to rethink my strategy. If I am to wrap important necessities into classes anyway, I might as well use an already made framework to save me some time (assuming processing time is the same).

If I am to say screw it and just code away procedurally (some OOP) I would have a lot more work on my hand should I decide to change something in the future (imagine trying to add functionality to all submit types for input tags if I wanted to add a script of some sort... impossible).

What's your take on the matter?
dev_php_11
Forum Newbie
Posts: 8
Joined: Tue Feb 02, 2010 11:48 am

Re: Frameworks, speed, and how fast compared to own-framework

Post by dev_php_11 »

In summary (quicker version):

If I am going to wrap code up into classes for quicker access and ease of use (MySQL query statements, etc.) and have that OOP design anyway, would I benefit from a pre-made framework? ie CodeIgnition?

Does OOP design hinder performance? C++ goes into machine code on compile. PHP is obviously slower in this respect since it is on the fly, so it seems as if OOP does matter in this situation.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Frameworks, speed, and how fast compared to own-framework

Post by Eran »

When was the last time you encountered performance issues under major load? compare that to the last time you had to change something in a project. Which comes up more often?
dev_php_11
Forum Newbie
Posts: 8
Joined: Tue Feb 02, 2010 11:48 am

Re: Frameworks, speed, and how fast compared to own-framework

Post by dev_php_11 »

Very true. I guess changing things in-code is much more common, and if I ever were to run into performance issues I could always scale it to more servers.

I am new to MySQL as well as PHP. From what I have been reading, it seems as if PHP would cause speed concerns before MySQL would. If I were to have one database accessed by multiple servers, all running PHP, MySQL should be able to handle all requests, should it not?
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Frameworks, speed, and how fast compared to own-framework

Post by alex.barylski »

I love how so many people buy into marketing hype. :P

Where on CI web site do they benchmark their framework against:

1. Zend
2. Symphony
3. Cake
4. Solar

Or any other??? They can't because without a ssolid understanding of each, you end up comparing apples to oranges. Don't choose CI based solely on what the web site says.

Yes OOP is slower in execution of code than procedural but the flip side, is OOP (once you are accomplished in the art AND science) will allow you to develop more reusable and robust code in less time. So the years spent invested in learning effective OOP, will eventually pay off in later years when you cut your competition in half. :P

Cheers,
Alex
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Frameworks, speed, and how fast compared to own-framework

Post by josh »

Also with OOP its easy to "swap out" strategies. Got a "service" thats consuming tons of memory because its loading entire domain models just to get a list of their IDS? No problem... write a new class that has the same inputs & outputs but uses more efficient algorithms and drop it in place. Like upgrading the engine in your car.

Trying to do that with any procedural code really would be like an car's engine overhaul (a whole lot of stuff to worry about). With OOP we talk in terms of "narrow interface" google that for example ;-)
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: Frameworks, speed, and how fast compared to own-framework

Post by JNettles »

2) I want to make everything scalable, meaning, if I want to write a "submit.php" file, rather than typing in html for an input tag: <input type="submit' name="submit" value="Log in" />

I can just do: submit->process("Log in")
Maybe its just late and I'm a little slow right now but I'm having trouble understanding what you're driving at with this. Are you saying that you want to be able to implement your controls solely with PHP and not have to play with HTML?

If that's the case I think most frameworks at least try to implement something along those lines or at least some sort of form builder. I always did enjoy the way Prado handled forms and controls, with the custom HTML tags and it made Ajax as simple as declaring it an active control.
dev_php_11
Forum Newbie
Posts: 8
Joined: Tue Feb 02, 2010 11:48 am

Re: Frameworks, speed, and how fast compared to own-framework

Post by dev_php_11 »

That's exactly it. My problem is I don't know much about anything, with PHP and mySQL being my starting points. I don't know anything about ajax, javascript, or any other part of web development.

I have been looking at some benchmarks (google php framework speed test) and they say something along the lines of the following:

HTML: 1300 requests per second
baseline php: 300 rps
code igniter: 25 rps
cakephp: 10 rps
zend: 8 rps

It seems as if baseline php is the only way to go. Why bother with a framework if they are this slow? Do requests per second even matter? How do sites like facebook handle millions of users then?

I want to create a stock market simulation program. Can I do that soley in PHP and mySQL, or do I need jscript and ajax for client side processing? My worries are about speed. Once I have thousands of users, would a php framework like codeigniter (or kohana) be beneficial or hinder performance?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Frameworks, speed, and how fast compared to own-framework

Post by Eran »

Forget those statistics. Most people performing those haven't the slightest idea how to generate meaningful numbers that can be duplicated on any system but their own. Those are very naive numbers, try to perform anything meaningful (not just some stupid loops) with baseline PHP and the difference becomes much smaller. Also, turn on APC for those tests and you see the difference crunches even further.

There is no way a ZF project can serve only 8 requests per second unless it is horribly configured. It just shows the level of competency of those benchmark takers with those frameworks.
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: Frameworks, speed, and how fast compared to own-framework

Post by JNettles »

My advice is to stop worrying so much about all this. If you're just learning then speed tests are the last thing you should be worrying about - those benchmarks are for people who actually rely on these systems for a living and require the best performance.
Post Reply