473,320 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DB - persistent connection?

For a low-ish traffic website that is doing the simple "build pages from
HTML templates and info in a database" kind of thing, do the wise folks in
this newsgroup advocate connecting and disconnecting from the DB with each
query, or maintaining a persistent connection in the session?

I guess my application could work either way, and I've gravitated towards
the connect-query-disconnect method, but not for any really good reason. It
struck me as simpler to stick with the stateless way of doing it. The only
obvious drawback I can see is the performance penalty, which I guess could
be large if the website gets busy.

What do other people think? Is there an obvious best practise on the merits,
or is it down to the application and developer?

--
The email address used to post is a spam pit. Contact me at
http://www.derekfountain.org : <a
href="http://www.derekfountain.org/">Derek Fountain</a>
Jul 17 '05 #1
3 3198
.oO(Derek Fountain)
For a low-ish traffic website that is doing the simple "build pages from
HTML templates and info in a database" kind of thing, do the wise folks in
this newsgroup advocate connecting and disconnecting from the DB with each
query, or maintaining a persistent connection in the session?
I open the connection when I create my database object and close it when
the object gets destroyed, usually at the end of the script. So it's
neither per-query nor real persistent, but simply per-page/per-request.
I guess my application could work either way, and I've gravitated towards
the connect-query-disconnect method, but not for any really good reason.


I wouldn't do that, and I wouldn't use real persistent connections
either, because it may waste server resources on a shared host. If you
have your own server then of course you can do whatever you want.

Micha
Jul 17 '05 #2
*** Derek Fountain wrote/escribió (Thu, 24 Feb 2005 10:26:58 +0800):
For a low-ish traffic website that is doing the simple "build pages from
HTML templates and info in a database" kind of thing, do the wise folks in
this newsgroup advocate connecting and disconnecting from the DB with each
query, or maintaining a persistent connection in the session?


I've seen low traffic sites go down for using persistent connections. You
can easily reach a limit of 100 connections used with hardly any visitor.
--
-- Álvaro G. Vicario - Burgos, Spain
-- Thank you for not e-mailing me your questions
--
Jul 17 '05 #3
On Thu, 24 Feb 2005 10:26:58 +0800, Derek Fountain <no****@example.com> wrote:
For a low-ish traffic website that is doing the simple "build pages from
HTML templates and info in a database" kind of thing, do the wise folks in
this newsgroup advocate connecting and disconnecting from the DB with each
query, or maintaining a persistent connection in the session?

I guess my application could work either way, and I've gravitated towards
the connect-query-disconnect method, but not for any really good reason. It
struck me as simpler to stick with the stateless way of doing it. The only
obvious drawback I can see is the performance penalty, which I guess could
be large if the website gets busy.

What do other people think? Is there an obvious best practise on the merits,
or is it down to the application and developer?


It Depends (tm) on how many distinct connections you use, where a connection
is defined by both the database and the username.

If all your applications on the server use a small set of user credentials
against a small set or one database, then persistent connections are great,
particularly for databases where connection is not particularly cheap (e.g.
Oracle).

If you access more than a small number of distinct username/database
combinations, persistent connections can be disastrous, as over time each
webserver child process will each build up a pool of connections to each of the
username/database combinations and hold them open.

I consider the fact that PHP's persistent database connection infrastructure
doesn't include a "disconnect after X seconds" feature a fairly nasty flaw -
surely you'd want your pool of connections to form a common working set of
connections, rather than holding open connections for eternity. This can
probably be mitigated by webservers' methods of recycling child processes;
MaxRequestsPerChild in Apache, or the equivalent methods of recycling worker
processes in IIS6, but this seems to be the wrong level to do this.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Randell D. | last post by:
Folks, I currently connect to my db with PHP code that uses non-persistent connections. I've read that persistent connections can help performance since a connection to the db will use an...
2
by: Steve Jenkins | last post by:
Wonder if anyone can help. So, I've read: >> http://uk2.php.net/function.mysql-pconnect >> http://uk2.php.net/manual/en/features.persistent-connections.php Can one seriously see persistent...
4
by: M. Katz | last post by:
I'm relatively new to PHP/MySQL and I've heard about maintaining a persistent connection to the database. To save overhead, I'd like to maintain the connection in a session variable, but I have a...
5
by: Felix E. Klee | last post by:
I've set up a PHP web application where users can log in and open a connection to a NNTP-server. There is a *one-to-one* relationship between sessions and NNTP-connections (i.e. exactly one...
16
by: Paul Rubin | last post by:
I've had this recurring half-baked desire for long enough that I thought I'd post about it, even though I don't have any concrete proposals and the whole idea is fraught with hazards. Basically...
6
by: David Rasmussen | last post by:
I use urllib2 to do some simple HTTP communication with a web server. In one "session", I do maybe 10-15 requests. It seems that urllib2 opens op a connection every time I do a request. Can I...
1
by: Paul Wagstaff | last post by:
Access 03 Runtime / Win XP Hi folks I wonder if I can tap the wizards for some general advice.. What are the risks/penalities/drawbacks for having a persistent connection to a back-end mdb? ...
5
by: ernie.bornheimer | last post by:
Hello I have a script that works but it shouldn't, and I would like to know why. I originally wrote it with a statement to connect to the database, then there's a part to select the database,...
9
by: mel | last post by:
Hi all, I need a persistent TCP connection with my web server over page reloads. This means that, even if the user goes to a different page (in my domain), I want to keep a TCP connection...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.