w4seem Posted July 27, 2006 Share Posted July 27, 2006 ok guys im trying to optimise my scripts to run faster, i need some help (noob) :(. im using phpmyadmin to access my info.here goes....1. is it better to have all my tables under the one database, or better to have multiple databases?2. most of my columns are varchar 255, is this ok or is char 255 better? (size isnt an issue, only speed)3. how do i index my database? iv read up on this but still a bit lost...4. in phpmyadmin i ran a simple search SELECT * FROM `searchbooks1` and the query returned results in 0.0009 secbut when i do this through my website, i.e search for books, it takes ages, is this a server issue?ok, thats it for now, unless there is anything i missed that will speed up my site.the site is studyleave.com (mentioned previosuly)any help would be very much appreciated.thanks Quote Link to comment https://forums.phpfreaks.com/topic/15817-php-speed-and-optimization/ Share on other sites More sharing options...
Ninjakreborn Posted July 27, 2006 Share Posted July 27, 2006 1, doesn't really matter I suppose it might help some.2. Lower most basic ones to varchar (80) instead, if it's something that won't require 80 characters limit it even more, whatever it's set to, it makes enough room in memory for that, you don't need it adding the extra memory use datatypes very wisely when building the database.3. Click on 1 field and click index, don't index more than 2 fields, or it does worst than good. 1-2 htat you call frmo a lot will make it faster.4. show your script. Quote Link to comment https://forums.phpfreaks.com/topic/15817-php-speed-and-optimization/#findComment-64756 Share on other sites More sharing options...
Barand Posted July 27, 2006 Share Posted July 27, 2006 [quote]1. is it better to have all my tables under the one database, or better to have multiple databases?[/quote]I suspect that joins within a single db are more efficient than those across db's, but that's a guess.[quote]2. most of my columns are varchar 255, is this ok or is char 255 better? (size isnt an issue, only speed)[/quote]char would be faster as you then get fixed length records. However only set the sizes to that required and not all 255. Query speed is proportional to to the amount of data returned so hundreds of unneccessary spaces is adding to the load,[quote]4. in phpmyadmin i ran a simple search SELECT * FROM `searchbooks1` and the query returned results in 0.0009 sec but when i do this through my website, i.e search for books, it takes ages, is this a server issue?[/quote]You were probably already connected to the server so didn't have the overhead of the connection. The longest part of a query is often the db connect. Just do it once per page.[code]ok, thats it for now, unless there is anything i missed that will speed up my site.[/code]Where possible use joins instead of subqueries or nested queries.. Quote Link to comment https://forums.phpfreaks.com/topic/15817-php-speed-and-optimization/#findComment-64887 Share on other sites More sharing options...
ToonMariner Posted July 28, 2006 Share Posted July 28, 2006 Only penneth to add is that creating a connection to a database uses huge amounts of system resources. Purely on a 'be nice to the server' basis I woudl stick to one database. They are built to take a bot of hammer so don't be scared of having 200 tables in a database - its nothing ;) Quote Link to comment https://forums.phpfreaks.com/topic/15817-php-speed-and-optimization/#findComment-64926 Share on other sites More sharing options...
w4seem Posted July 30, 2006 Author Share Posted July 30, 2006 this is all great feedback, im testing it out now and will give feedback, thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/15817-php-speed-and-optimization/#findComment-65943 Share on other sites More sharing options...
w4seem Posted July 30, 2006 Author Share Posted July 30, 2006 just another question plz...should i have my website on the same server as the db ? if i keep it seperate willit be more efficient?hmm i guess its financial issues too but ill take he hit if its worth it. Quote Link to comment https://forums.phpfreaks.com/topic/15817-php-speed-and-optimization/#findComment-65944 Share on other sites More sharing options...
Barand Posted July 30, 2006 Share Posted July 30, 2006 Better performance with dedicated db server Quote Link to comment https://forums.phpfreaks.com/topic/15817-php-speed-and-optimization/#findComment-66038 Share on other sites More sharing options...
Koobi Posted July 30, 2006 Share Posted July 30, 2006 most of the things mentioned in this thread are the main things you want to consider for optimization.but there are other tiny things that can add up and eat up a lot of time.if you follow general good coding practice, you should be ok.but there are also other things...things like, using double quotes and single quotes appropriately. not using regular expresions when you can use string functions. running PHP as an Apache module or as a CGI. Quote Link to comment https://forums.phpfreaks.com/topic/15817-php-speed-and-optimization/#findComment-66069 Share on other sites More sharing options...
Barand Posted July 30, 2006 Share Posted July 30, 2006 Really shaving off the microseconds there, Koobi Quote Link to comment https://forums.phpfreaks.com/topic/15817-php-speed-and-optimization/#findComment-66070 Share on other sites More sharing options...
Koobi Posted July 30, 2006 Share Posted July 30, 2006 [quote author=Barand link=topic=102083.msg406127#msg406127 date=1154287205]Really shaving off the microseconds there, Koobi[/quote]hehe yeah :)i think it really depends on the situation though. like for example, in this process i'm creating, i would have to loop through something almost 3 million times and 3 million micro seconds can add up but that's an extreme case.don't think you'd really have to do the things i mentioned in my post, w4seem, just thought i'd cover all bases. you should be fine following the rest of the posts before mine :) Quote Link to comment https://forums.phpfreaks.com/topic/15817-php-speed-and-optimization/#findComment-66073 Share on other sites More sharing options...
Barand Posted July 30, 2006 Share Posted July 30, 2006 Here's one other thing I found to have a significant effecthttp://www.php-editors.com/contest/1/49-read.htmlEDIT: oops. wrong link in my clipboard, corrected now. Quote Link to comment https://forums.phpfreaks.com/topic/15817-php-speed-and-optimization/#findComment-66076 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.