Jump to content

Archived

This topic is now archived and is closed to further replies.

w4seem

php speed and optimization

Recommended Posts

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 sec

but 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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[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..

Share this post


Link to post
Share on other sites
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 ;)

Share this post


Link to post
Share on other sites
this is all great feedback, im testing it out now and will give feedback, thanks guys.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[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 :)

Share this post


Link to post
Share on other sites
Here's one other thing I found to have a significant effect

http://www.php-editors.com/contest/1/49-read.html

EDIT: oops. wrong link in my clipboard, corrected now.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.