Re: One Global Connection vs. Open-Close



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.

.



Relevant Pages

  • Re: hitting the limits
    ... relatively straight forward MySql database. ... 10K visitors a month and an 80Mb database are nothing. ... heavily loaded server. ... But the connection will hang around until the garbage ...
    (comp.lang.php)
  • Re: VFP8 & MySQL
    ... > VFP functions like NVL to a MySQL one, definitely it made the switch very ... > About your connection problem, I have mine setup as default for 100 ... As for the server, we left it ... The server crashed and corrupted the database. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: VFP8 & MySQL
    ... Main Location and 3 branches (these are remotely accessing MySQL at the main ... About your connection problem, I have mine setup as default for 100 ... As for the server, we left it alone. ... The server crashed and corrupted the database. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Java and MySql program example ?
    ... > I am trying to learn Java and need an example program with MySql ... > MySql database. ... Database connection established ...
    (comp.lang.java.programmer)
  • Re: OdbcDataReader
    ... I did as you told and i find out that the connection to the MySql ... database closes and if i go to the MySql mamager i not able to open it ... >> While the odbccommand is reading the Access table I open the other ...
    (microsoft.public.dotnet.languages.csharp)