[Resolved] Optimise in PHP?
Moderator: General Moderators
[Resolved] Optimise in PHP?
Just a quickie... how would I optimise the database (just a certain table) in PHP ??
Also is it harmful to keep optimising it??
Also is it harmful to keep optimising it??
Last edited by Dale on Wed May 03, 2006 1:50 am, edited 1 time in total.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
No it is not. Optimization is a large discipline. There are many reasons why code may run slowly and even more possible solutions to such problems. So to be of real help you will have to be more specific with your question and present us with the relevent code and database structure.Just a quickie...
PHP is generally faster that any database so it does make sense to outsource database operations to PHP although the possibities for doing this are severely limited.how would I optimise the database (just a certain table) in PHP ??
It is never harmful to optimize, unless of course you do it wrong. Its good to get into the habit of simple optimizations but even this will require knowledge of what executes quickly what does not. The larger the system, and the more performance you demand from it, the more complex the optimizations become. You can be assured that Google, Microsoft, and Yahoo have whole departments dedicated to optimization despite performance already being intrinsic to all their software design.Also is it harmful to keep optimising it??
I believe the best, and quite possibly the easiest, form of optimization is optimization by design. That is, optimized code resulting from decisions made, with the benefit of experience, before you begin to write any code. Anything less will lie somewhere between a hack and redesign depending on your programming ability and strength of motivation.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
A well laid out database design will save you tons of headaches and redesign time in the future. As far as using PHP to optimize your MySQL database (this is for MySQL only), I would download phpMyAdmin and see how they process index and key requests as part of their script.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
This is relevent. Its about a fairly large project and how they found they could use PHP to optimise database performance. They don't go into any specifics unfortunately.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Maybe Dale means:
Code: Select all
function optimize_mysql_table($dsn, $db, $table) {
mysql_connect($dsn);
mysql_select_db($db);
mysql_query("OPTIMIZE TABLE $table");
}(#10850)
About time someone answers the damn question. Everything doesn't have to be debated just for the sake of showing how big your smurf is. It's a pretty simple answer.
Code: Select all
OPTIMIZE TABLE `TableName`- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Thats not called for.agtlewis wrote:About time someone answers the damn question. Everything doesn't have to be debated just for the sake of showing how big your smurf is. It's a pretty simple answer.
Code: Select all
OPTIMIZE TABLE `TableName`
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Funny thing is, I never even considered this. This is the absolute best answer for the original poster.arborint wrote:Maybe Dale means:Code: Select all
function optimize_mysql_table($dsn, $db, $table) { mysql_connect($dsn); mysql_select_db($db); mysql_query("OPTIMIZE TABLE $table"); }
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Thank you very mucharborint wrote:Maybe Dale means:Code: Select all
function optimize_mysql_table($dsn, $db, $table) { mysql_connect($dsn); mysql_select_db($db); mysql_query("OPTIMIZE TABLE $table"); }
However thanks to everyone else too that has provided me with some new knowledge.