44 Comments
- awok, on 10/12/2007, -1/+13Okay, this article doesn't really help you make anything 'lightning fast'.
For those of you who are just getting into php, i humbly recommend the following guides:
[php caching to speed up dynamically generated sites]
http://www.theukwebdesigncompany.com/articles/php-caching.php (very useful)
[step by step guide on how speeding up your php scripts by making use of built-in debug commands]
http://phplens.com/lens/php-book/optimizing-debugging-php.php (awesome for naps and pr0s alike)
[5 tips to...]
[..speed up your existing site]
http://paulstamatiou.com/2006/06/22/5-ways-to-speed-up-your-site/
[..speed up development]
http://www.phpit.net/article/5-tips-to-speed-up-php-development/
this one expands on lcarsdeveloper's ramblings :P
[optimising mysql queries for php]
http://www.dublish.com/articles/10.html
Hope this helps all you freaks out there learn the best web language out there.
edit: HAHAHA ASP is terrible in comparision to php in every way - rastan, on 10/12/2007, -0/+7Especially since something like an opcode cache like APC or eAccelerator is going to net you a thousand times more performance improvement than tweaking your variables.
- Snowcone, on 10/12/2007, -0/+6I think I agree with Jeff Moore's comment about maintainability and correctness above speed. You can always optimize after the fact, but it is infinitely harder to go back and reorganize a program to be maintainable.
- mjar81, on 10/12/2007, -1/+7When did this turn into an ASP vs. PHP discussion?
The article is about PHP optimization. Stay on topic or i'll flog you with a wet noodle. - eklass, on 10/12/2007, -0/+5I can appreciate analysis such as "Incrementing an undefined local variable is 9-10 times slower than a pre-initialized one." But it really doesn't say anything about the speed of initializing a local variable and then incrementing it, which I think is a more fair comparison.
Properly setting your php.ini to display notices can help users to write better (stricter) code, thereby fixing some of the problems in the aforementioned article. - evilTak, on 10/12/2007, -0/+5No, a good reason to make local variables is that it's good programming practice.
- ForbesBingley, on 10/12/2007, -0/+5And in related totally obvious tips & advice: be sure to place a dollar symbol before your variable names...
- merreborn, on 10/12/2007, -2/+6As someone who actually has a clue, and designs and maintains dozens of mysql databases with millions of rows on dozens of servers, I can tell you conclusively that mysql DOES indeed stop searching after collecting 1 row in the given example query, "SELECT * FROM table WHERE id=5 LIMIT 1"
However, there are also cases in which mysql must find the entire result set before returning data: specifically, if you add an ORDER BY clause. For example, "SELECT * FROM table ORDER BY username LIMIT 5" requires that mysql first sort the whole table, then return your 5 results.
Awok clearly doesn't have a clue, seeing as he acts as if indexes are some great secret of MySQL. _EVERY_ RMDBS has indexes! Please, don't offer advice on subjects you know nothing about. - lcarsdeveloper, on 10/12/2007, -0/+4Didn't find this list all that useful, but that's just me.
I've found simple things such as writing good SQL can help improve performance a lot, that's what has caused me a lot of slow pages. For example, if you're displaying one record on a page, use LIMIT:
"SELECT * FROM table WHERE id=5 LIMIT 1"
That way if you're displaying the fifth row out of 100,000, it will stop searching after it finds the first match. And I realise MySQL is only semi-related to the article. - cazabam, on 10/12/2007, -0/+4I was going to post a detailed explanation about how wrong this article is, but the comment by Jeff Moore sums it up nicely. There are so many articles timing the microsecond differences between slightly different techniques, and yet 100% of the time the performance issues lie in I/O, database waits or badly factored loops or recursion.
- mutant, on 10/12/2007, -0/+3This is a pretty weak digg.
- PrisonerOfPain, on 10/12/2007, -0/+2"If you are going to troll do it right. Compare PHP it to ASP.NET :-P"
PHP will lose. - mjar81, on 10/12/2007, -1/+3Agreed.
Not limiting results of SQL queries is probably the #1 reasons that php classes/functions are slow.
As for these tests the guy did, he had to loop the programs 1000+ times to get measurable results.
I'm all for optimizing my programs, but does a difference of 0.0001 seconds really matter? (when you're only calling the thing once, not thousands of times like the article author does) - vincentb, on 10/12/2007, -1/+3I have been profiling huge PHP applications and it is exactly what comes out: 60% of the execution time is wasted in I/O and database access.
I don't like these stupid optimizations. It's like the guy who uses a 16-bit integer instead of a 32-bit, just to save memory but who forgot computers are 32-bits nowadays. - trutwin, on 10/12/2007, -0/+2@BobTurbo
"Yea there are so many ASP articles on Digg, I couldn't choose which one to comment in."
Interpreted as sarcasm - if that's the case, find some and submit them then instead of complaining. - mjar81, on 10/12/2007, -1/+3great links, awok. Thanks!
- inkubux, on 10/12/2007, -0/+2Because java can't be optimized to be fast, so you don't have to worry ??
- lcarsdeveloper, on 10/12/2007, -0/+2I didn't think it did, but I could be wrong...
Anyone know for certain? - Grimdotdotdot, on 10/12/2007, -5/+6It's a bit, well, obvious, isn't it?
- cakefart, on 10/12/2007, -0/+1Absolutely. None of this makes any difference in comparison to a good query.
If you really want to speed up your web-apps, structure your app into a MVC pattern and get the controller part moved into Stored Procedures and Triggers. - TheSiz, on 10/12/2007, -0/+1horrible article. no digg.
- Grimdotdotdot, on 10/12/2007, -1/+2I thought SQL limited *after* it had collected all the results?
- awok, on 10/12/2007, -2/+3LIMIT 0,1 is only performed after mysql has queried all results.
If you want to speed up execution times significantly (and have a few extra kb's spare on your database) i HIGHLY recommend using an index on the rows you use most.
http://www.google.com/url?sa=t&ct=res&cd=3&url=http%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.1%2Fen%2Fcustom-engine-index-overview.html&ei=FSfGRNm2KM_KRd2z6fUM&sig2=_XxVpTpd43Zna0n2uZRGkg
INDEXing a row will create a hash of all instances, thereby eliminating the need to search the entire table everytime you make a SELECT.
When i stumbled upon the mysql documentation on INDEXES it was a lifesaver.
I was developing a website that stored all apprenticeships/courses/degrees for the midlands here in the UK, it was about 500'000 rows, and consisted of about 20-30 db selects every second (the frontend was a website for students accross the country).. anyway it would take 6seconds to populate the list from the frontend, but when i put a few INDEX's up it went down to 0.03 seconds (captured using php-benchmark)
Anway i was still kinda new to the whole php mysql thing back then, and have since learnt more ways to optimise, however for those of you just starting out, like i was, this could be a lifesaver. - adolfojp, on 10/12/2007, -0/+1C is not an object oriented language. You meant to say C++
- RevEng, on 10/12/2007, -0/+1I'm not hammering on Java here, but since when do you not have to worry about things like this in Java? Java has objects, inheritance, local and global variables. All of these things apply equally to Java as they do to PHP.
Of course, none of these optimizations really matter anyway. As already mentioned, I/O and algorithms are the important parts. Many of the optimizations he mentions (such as putting methods in derived classes instead of base classes) are essential parts of maintainability and design; changing them for the sake of saving a few clock cycles is no different than throwing the baby out with the bathwater. - Fish123456, on 10/12/2007, -0/+1I've learned more from these comments than from the actual article. That's why I don't like burying stories. In some instances, comments and opinions are worth just as much as or more than the linked article.
- PrisonerOfPain, on 10/12/2007, -0/+1"but since when do you not have to worry about things like this in Java?"
Since when do you _really_ need to worry about those things at all? - gdonald, on 10/12/2007, -0/+1Here are are some actual benchmarks:
http://destiney.com/benchmarks - PrisonerOfPain, on 10/12/2007, -0/+1Doesn't mean you can't user object oriented techniques in C.
- analgesia, on 10/12/2007, -1/+2limit has no effect here since ID is most likely a primary index (if the DB is set up right).
- Ashe, on 10/12/2007, -1/+1That article is inaccurate and outdated. In fact, it's a verbatim of a 5-year old article from John Lim. Read the original article at http://phplens.com/lens/php-book/optimizing-debugging-php.php
Most of the advices given in that article DO NOT apply anymore. Please digg this comment so that begginners won't use them blindly, thank you. - adolfojp, on 10/12/2007, -1/+1ASP should be slower than PHP. It is old, obsolete, deprecated and unsupported.
If you are going to troll do it right. Compare PHP it to ASP.NET :-P - RazorCrusade, on 10/12/2007, -0/+0Yeah, this article is really pretty terrible. There's no explanation for which tests were performed or how and there's no basis for any of the numbers (how much is three times slower when we don't know what it's slower than?). If this guy is advocating always using local variables instead of class methods, then he's only perpetuating terrible design practices.
- adolfojp, on 10/12/2007, -1/+1Yours was an informative comment. Why oh why did you have to ruin it with an ASP troll at the end?
- esquilax, on 10/12/2007, -0/+0at the same time, if you choose the wrong data structure to solve a problem, you could be up a tree when you go to optimize later. that's not the type of optimization the article is talking about, though.
- cplusplus, on 10/12/2007, -2/+2This article is stupid...
"Incrementing a global variable is 2 times slow than a local var."
That is not a good reason to make local variables. I trust incrementing any kind of variable is pretty fast now-a-days. - jo42, on 10/12/2007, -2/+1> article that explains simple steps you can take to speed up your PHP objects.
Write them in C? - evilTak, on 10/12/2007, -3/+1"I'm all for optimizing my programs, but does a difference of 0.0001 seconds really matter?"
Yes, when you're running on a production webserver with thousands of simultaneous users. - ephemerae, on 10/12/2007, -3/+1It's stuff like this that makes me glad I moved to Java.
- TalenKlaive, on 10/12/2007, -4/+1Not bad, dugg.
- triplah, on 10/12/2007, -8/+3[insert random fanboy comment about ruby]
- BobTurbo, on 10/12/2007, -6/+1Yea there are so many ASP articles on Digg, I couldn't choose which one to comment in.
- Twillight, on 10/12/2007, -6/+0From personal experience (my school had an ASP.NET course selection thingie recently), PHP beats ASP & ASP.NET in terms of speed. though this might have been affected by the imperfect coding of the teacher who wrote it... In terms of speed of development, however, ASP.NET 2.0 seems to be pretty easy, with their drag and drop stuff.
- BobTurbo, on 10/12/2007, -16/+0Convert them to ASP


What is Digg?