Re: MySQL close connection, what's the purpose?

From: Date: Sun, 02 Apr 2006 01:37:04 +0000
Subject: Re: MySQL close connection, what's the purpose?
References: 1 2 3 4 5 6 7 8  Groups: php.general 
Request: Send a blank email to php-general+get-233075@lists.php.net to get a copy of this message
On Sat, 2006-04-01 at 20:15, tedd wrote: > >Time. Opening a db connection is time consuming. There are many levels > >involved (making the connection, authentication, etc).. Even worse if > >the connection is over tcp/ip because that overhead comes in on top as > >well. > > Have you timed it? > > It would be interesting to actually run a script that opens, > retrieves, and inserts data -- let's say 50k times. What's the time > difference between one open, 50k retrieves/inserts, and one close-- > as compared 50k opens retrieve/insert closes? > > Maybe I'll do that tomorrow. > > > > You see, my habit stems from doing a lot of communication programming > >> -- it was my experience that you open a communication port > >> (file/channel/port/whatever); establish a link; exchange data; and > >> close it. There's no need to leave it open. > > > >Just because you can close it doesn't mean you have to. > > Everyone has their own way. I'm not going to advocate either style since both have their merits depending on where and what you are doing. My input is to advocate a database wrapper layer such that the database connection semantics are remove from general development. In this way you might have the following: <?php $conn = DbConnFactory::getConnection( $params ); $conn->query( 'INSERT INTO blah blah blah' ); $conn->free(); // this may or may not close the connection. ?> This way, if your mileage varies with either technique you can modify the connection layer to get another semantic which better suits your application/environment. Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'

« previous php.general (#233075) next »