472,805 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 3161
.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
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.