|
Posted by Jerry Stuckle on 04/29/07 16:11
john 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
>
(Hit send too fast)
As for connection pooling - yes, I've seen this being recommended in SQL
Server also - but I've found it's only good when you have a lot going on
- same with PHP and MySQL.
The reason is - with connection pooling, you are allocating server
resources all the time - whether they are needed or not. And you have
to allocate at least as many resources as you may *ever* need - and
should allocate more, just as a buffer. So, fir instance, if you at
some peak time you might need 200 connections concurrently, you need 200
connections in the pool all the time.
It's more important with SQL Server because it takes longer to connect
to the server. MySQL is a lot more efficient in that respect, and while
under certain conditions pooling (or persistent connections) might help,
you won't find the gain you do with SQL Server.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|