Welcome to Geeklog, Anonymous Saturday, November 30 2024 @ 07:44 pm EST

Geeklog Forums

Database connection suggestion


Tulkas

Anonymous
thoughtful
I was digging through the code, today, and noticed that each and every query opens and closes its own database connection. Isn't this a little overkill? For a page with a lot of queries, this means that a database connection is opened and closed many times during the load process of that one page.

I believe that my site is getting some poor results, from this, and my provider (dreamhost) limits the number of database connections a site can have.

Actually, they assign 25 "points" for every connection you open, and 1 "point" for every query, so one geeklog query is actually 26 points. I have a limited number of points allocated to me for each month.

So, with the current system, it seems like many pages will cost well over 100 points to load, when they could theoretically be done in under 40.

Have you thought about opening a database connection at the top of each page (include the code in some header), perform all the queries for that page using that connection, and then close the connection in the footer of the page? It seems like that would be much more efficient.

Please correct me if I am wrong.
Thanks.
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
To quote from the PHP manual:

If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned.


bye, Dirk
 Quote

Tulkas

Anonymous
Excellent. Thanks, Dirk!
 Quote

All times are EST. The time is now 07:44 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content