Jump to content


Photo

php speed and optimization


  • Please log in to reply
10 replies to this topic

#1 w4seem

w4seem
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 27 July 2006 - 04:56 PM

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

#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 27 July 2006 - 06:37 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 27 July 2006 - 11:41 PM

1. is it better to have all my tables under the one database, or better to have multiple databases?

I suspect that joins within a single db are more efficient than those across db's, but that's a guess.


2. most of my columns are varchar 255, is this ok or is char 255 better? (size isnt an issue, only speed)

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,

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?

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.

ok, thats it for now, unless there is anything i missed that will speed up my site.
Where possible use joins instead of subqueries or nested queries..

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 28 July 2006 - 01:19 AM

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 ;)
follow me on twitter @PHPsycho

#5 w4seem

w4seem
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 30 July 2006 - 04:12 PM

this is all great feedback, im testing it out now and will give feedback, thanks guys.

#6 w4seem

w4seem
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 30 July 2006 - 04:16 PM

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.

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 30 July 2006 - 05:53 PM

Better performance with dedicated db server
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 30 July 2006 - 07:17 PM

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.

#9 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 30 July 2006 - 07:20 PM

Really shaving off the microseconds there, Koobi
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#10 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 30 July 2006 - 07:25 PM

Really shaving off the microseconds there, Koobi


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 :)

#11 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 30 July 2006 - 07:33 PM

Here's one other thing I found to have a significant effect

http://www.php-edito.../1/49-read.html

EDIT: oops. wrong link in my clipboard, corrected now.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users