LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-28-2005, 09:58 AM   #1
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Rep: Reputation: 18
webpage development - when to open database?


Hello,

I'm currently developping a php - html webpage with a mysql database.
I'm wondering about the following: do you open the database link as soon as the page opens and close it when the page is closed? Or do you just open the db whenever data is needed from it and close immediately afterwards?
I'm just wondering about the latency times etc.

thanks,
Lieven
 
Old 02-28-2005, 10:28 AM   #2
csfalcon
Member
 
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

Rep: Reputation: 31
I keep the database connection open for as long as my website is running. Openning and closing database connections is expensive.
 
Old 02-28-2005, 11:47 PM   #3
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Depends on your requirements. If there aren't a lot of queries per page, I open and close on the spot. For projects that have a lot of queries (particularly on a single page) then I perfer per page opening/closing or persistant connections.
 
Old 03-02-2005, 01:15 PM   #4
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Original Poster
Rep: Reputation: 18
Just what I thaught. :-)
On my site, db will be used often so I'll connect and leave it open.
thanks.
 
Old 03-07-2005, 02:38 PM   #5
machron1
Member
 
Registered: Mar 2005
Posts: 34

Rep: Reputation: 15
I don't know if you can apply it to PHP, but in enterprise J2EE you normally rely on container-managed connection pooling. Connection pooling is basically a managed set of connections that are kept open. If this is not available, then one must use their own method of connection pooling. I've heard you can use C++ or Java classes in PHP (I'm not a PHP programmer) but if this is true, you can use one of the many connection pool classes available.
 
Old 03-07-2005, 02:43 PM   #6
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Thought it's not common in "vanilla" PHP, I've seen a couple of decent connection pooling setups on some commercial projects. Can't remember specific urls of the top of my head, but they are out there...

You could also write your own.
 
Old 03-07-2005, 02:50 PM   #7
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Original Poster
Rep: Reputation: 18
hmm... a little bit over my head I think.
What I'm doing now is creating a database class, which contains some methods to connect, disconnect, set some parameters like the db location, user, ... and then at the beginning of my script, I make an instance of this class and have it connect to the database returning a link resource.
That single (I hope) resource is then used for all my queries and at the end of the script, I disconnect from the database and free the resource.

I don't think that this is a persistant db cnx, every time the page is requested, it runs the script and thus opens and closes the connection?

thanks anyway. I learn every day.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Development environment for database based web service Spenny Programming 3 10-26-2005 09:22 AM
Novell to Open SuSE Pro for open development HenchmenResourc Linux - News 0 08-02-2005 10:57 PM
Open source development gets paid marghorp General 0 06-06-2005 08:11 AM
More Open Source software development corbis_demon Linux - News 2 10-07-2004 01:31 AM
Looking for open source development tools martinig Programming 3 10-06-2002 11:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration