Is connection pooling worth the effort???

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Is connection pooling worth the effort???

Post by raghavan20 »

I was working on a rollback issue and finally found that the rollback did not work properly because another database wrapper was using a different dB connection and I had to pass the connection to get it work and I was thinking, is database connection pooling worth the effort and at a superficial point of view, eveybody knows that it can avoid lot of server connections but there are more hidden problems in it...

i came across an article and this has cautioned me before implementing connection pooling...
There are a couple of points that should be considered before using pooled connections. It is possible that if used incorrectly this can produce a security risk, or at least introduce problems. If your web server using PHP (for example) and pooled connections, does things to the connection, that leaves it it a different state at the end to how it started, you shouldn't use pooling. Lets take a example of this. Assume you have a page that requests a password from a user, then using this password, alters the default database to one that other users are not allowed access to, if this connection is reused by another user, they will have access to data they should not be allowed to see.
so I would request your views on the topic and suggest me the best ways to do pooling or if you are against pooling, please explain your opinions...
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

It sounds like your problem was not with connection pooling but instead with connection management. As for connection pooling (or persistent connections as they are called) in general I do the following:

1. I start with standard connections (creating a new connection each <db>_connect() call)

2. If I start running out of connection I tune the database and OS setting to try to solve the problem.

3. If there are still problems with connections and I see that connections are occuring in a way that pooling might help and #2 did not solve the problem, then I try pooling (an change the database/OS setting accordingly).
(#10850)
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

have you come across any good tutorials which talk about PHP and Mysql connection management???

anyway, thanks very much for your answers.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I don't know if I have ever read any tutorials on managing your connections. You seemed to have found your problem, which you said was "because another database wrapper was using a different dB connection." It seems like using multiple database wrappers is probably the only reason why you would have that problem.
(#10850)
Post Reply