Reply to Re: One Global Connection vs. Open-Close

Your name:

Reply:


Posted by Chung Leong on 04/30/07 10:18

On Apr 29, 2:56 pm, john <puop...@gmail.com> 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.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация