View Full Version : Persistent Connections

07-10-2003, 12:12 PM
Persistent connections seems to raise it's dark-side occaisionally, as recently seen again here :

Having already expressed concerns about the original OR code calling PConnect() & Close() I haven't been able to let the matter rest.

No reply as yet from the author of ADOdb, so have been reading the PHP documentation (I need a life):

A brief summary from php.net:

If persistent connections don't have any added functionality, what are they good for?

The answer here is extremely simple -- efficiency. Persistent connections are good if the overhead to create a link to your SQL server is high.

Note, however, that this can have some drawbacks if you are using a database with connection limits that are exceeded by persistent child connections. If your database has a limit of 16 simultaneous connections, and in the course of a busy server session, 17 child threads attempt to connect, one will not be able to.

If there are bugs in your scripts which do not allow the connections to shut down (such as infinite loops), the database with only 16 connections may be rapidly swamped.

While there may be no immediately clear answer to my original concerns about OR's use of PConnect, it does appear that the issue may require closer scrutiny.

I know I will be goig over my code again, and considering alternatives.

07-10-2003, 02:50 PM
If you hear back from the ADODB author let me know what they say.. I will look into this when i have a chance. It is simple to switch to using just Connect instead of PConnect, there is one variable to set.. ANyways, I will look into this, as i look into redoing a mojor portion of the open-ralty code for the next release

Fat Lizard
07-10-2003, 03:08 PM
Will let you know if and when I hear, but the php.net documentation about PConnect is interesting..


Fat Lizard
07-11-2003, 01:34 PM
Good questions. All the issues are managed by PHP internally. PHP has a resource manager that keeps track of all connections.

>Are there errant or invalid pointers left?

PHP keeps an internal count.

>What is the potential for memory leaks (depending on what happens above)?

No memory leaks. PHP keeps a count internally and frees as appropriate.

> Would it be better and more robust to check for the existance of the class before calling it's methods, >instantiating the class only if doesn't exist, and then, closing it each time?

PHP already does checking, and will generate an error message as appropriate.

Hence it would appear a major influence is the importance an author wishes to place on PHP's documentation : http://php.net/manual/en/function.msql-pconnect.php

What works on one server, may cause problems on another which offers less connections ..

One size may not fit all

02-27-2004, 06:22 AM

I have had a problem with pconnect and changed to connect instead in the ADODB library. It seems to work fine (so far) and was just a case of altering the common.php file at the very end.

// this is the setup for the ADODB library
$conn = &ADONewConnection($db_type);
$conn->PConnect($db_server, $db_user, $db_password, $db_database);

change to:

// this is the setup for the ADODB library
$conn = &ADONewConnection($db_type);
$conn->Connect($db_server, $db_user, $db_password, $db_database);

My host was telling me that we had multiple connections left open and evetually it though up an error taking the site out of action. Am using an old version of Jons code v3. but maybe this is something to think about.

If anyone thinks this is not a good idea please let me know as I would be interested in my peers opinions :wink:

contact at bobharrison dot net

many thanks and keep up the good work

02-27-2004, 01:13 PM
the problem with using Connect() is that you should Close() the connection. Where as PConnect is highly efficent for sites like OR because it uses continued connectivity to the database on everypage and eliminates much of that start up time :)

I do agree however that an alternative should be in place... probably just a flag, and I think adodb might already have this in place where you can just change a value to never allow PConnect and it will act as Connect.