Minimize connection to mysql as possible

Discussion in 'PHP' started by d1srupt3r, Dec 23, 2010.

  1. #1
    Hi guys! I am having some issues with my php script. My webserver usually complains that my script uses a lot of server load. So I am suspecting that my site uses too much mysql connection since I am using an ajax-driven dictionary. My website is www.defineitfast.com, upon typing the word, a word suggestions appears on the right side bar which has separate mysql connection then when a definition is on the db, it will appear instantly which uses another mysql connection. If a lot of visitors uses the site simultaneously it may give a lot of load to the server(maybe?). Any suggestion on how to fix this problem?:confused:

    Does using mysql_close() on every query fixes this? Or is there a global sessionid on a specified time for the connection on mysql? I am not pro at php and I am still on the process of learning. Please enlighten me. Thank you so much guys!
     
    d1srupt3r, Dec 23, 2010 IP
  2. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #2
    Try adding a limit to the word suggestion like:
    "SELECT word FROM tbl_dictionaray where word LIKE '$word%' LIMIT 5;"

    and select just the table fields you need. This will reduce the amount of data transferred
     
    shofstetter, Dec 23, 2010 IP
  3. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #3
    sometimes it helps. Try to optimize mysql queries.
     
    olddocks, Dec 24, 2010 IP
  4. d1srupt3r

    d1srupt3r Peon

    Messages:
    79
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for the advices. I tried to optimize the quesries and just use 1 sql login for both glossary look up and word suggestion. That may lessen the load maybe? :)
     
    d1srupt3r, Dec 25, 2010 IP
  5. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #5
    Singleton...
     
    guardian999, Dec 26, 2010 IP
  6. Alastair Gilfillan

    Alastair Gilfillan Active Member

    Messages:
    120
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #6
    It should only be connecting once - not per query/search. The load will be coming from AJAX hammering your (possible large?) database for search suggestions; it's the number and size of the queries that's slowing things down. DefineItSlowly.com? ;)
     
    Alastair Gilfillan, Dec 26, 2010 IP
  7. d1srupt3r

    d1srupt3r Peon

    Messages:
    79
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yup, you have a point. The AJAX may also be the cause since I also have 50mb+ of sql database for the dictionary. Maybe I'll try to use heuristic search and using cache for common word search. Can anyone point me on a tutorial for caching? DefineItSlowly.com? Naaah.. Hahaha..
     
    d1srupt3r, Dec 26, 2010 IP