[Mimedefang] Mysql connections

Jan-Pieter Cornet johnpc at xs4all.nl
Thu Dec 14 09:01:15 EST 2006


On Thu, Dec 14, 2006 at 07:13:56AM -0500, David F. Skoll wrote:
> > You can do anything you want, as long as you open the connection in
> > filter_initialize(), and close it in filter_cleanup()
> 
> That's one strategy.  I prefer to "lazily" open and close the connection.
> That is, have a wrapper function called "get_mysql_handle" that checks if
> there is an existing handle, and returns it if so.  Otherwise, it opens
> a connection and caches the handle in a global variable.

so... something like DBI->connect_cached
 
> This function can also do a "ping" test and close and reopen the handle
> if the ping test fails.  That way, if someone restarts the MySQL server,
> the MIMEDefang slaves can react properly by closing and reopening the
> connection automatically.

You mean, something like DBI->connect_cached

I think I see a pattern :) The DBI documentation may be a bit cryptic,
but "connect_cached" actually does all this: it gives you the cached
handle, calls "ping" on it, and if it fails, reconnects.

So to answer the OP: if you just replace your current "DBI->connect"
calls with "DBI->connect_cached" calls, you're fine. This will keep
the connections open, opening "lazily", and automatically checking if
the connection is still active when you need it.

-- 
Jan-Pieter Cornet <johnpc at xs4all.nl>
!! Disclamer: The addressee of this email is not the intended recipient. !!
!! This is only a test of the echelon and data retention systems. Please !!
!! archive this message indefinitely to allow verification of the logs.  !!



More information about the MIMEDefang mailing list