Re: One Global Connection vs. Open-Close
- From: Chung Leong <chernyshevsky@xxxxxxxxxxx>
- Date: 30 Apr 2007 03:18:08 -0700
On Apr 29, 2:56 pm, john <puop...@xxxxxxxxx> wrote:
All:
I have a MS background and am having fun in the open source world of
PHP and MySQL --- and I have a question.
With PHP and MySQL, is it considered better practice to open a single
database connection and re-use it throughout the life of the
application (simple Web application - low traffic), or is it better to
open a connection, use it and close it as needed?
(With SQL Server, you'd do the latter, because connection pooling and
other optimization mechanisms help ensure that connecting to the
database is low cost.)
Thanks,
John
jpuopolo
It's not so much a better practice as the only practice: In PHP, you
can't create a connection that last beyond the current request. So you
have to reestablish the connection everytime. There is this feature
called persistent connection in PHP but it should be avoided like the
plague. It has a way of leading to connection failures and the saving
is negligible when the database is hosted on the same server.
Even without connection pooling, one should close the connection as
soon as it isn't need as there's a limit to the number of concurrent
connections in MySQL.
.
- References:
- One Global Connection vs. Open-Close
- From: john
- One Global Connection vs. Open-Close
- Prev by Date: Re: help on integrating RSS in site done in php
- Next by Date: Re: help on integrating RSS in site done in php
- Previous by thread: Re: One Global Connection vs. Open-Close
- Next by thread: Authorization code for access to administration - Dialog ask for login and password three times then the authorization failed although I entered correct pw and login
- Index(es):
Relevant Pages
|