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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux