[Dbix-class] Apache::DBI and DBIx::Class
Matt S Trout
dbix-class at trout.me.uk
Wed Apr 5 20:54:18 CEST 2006
Mark Hedges wrote:
> I've always found in a handler that you have to "connect" at
> the beginning of every request, because sometimes the child
> sits around until the database times out the connection.
> (Which is a good thing, unless you have unlimited DB memory.)
DBIC already handles that.
> Calling DBI->connect is the best way to get Apache::DBI to
> ping the database handle and reconnect if it went away.
> Apache::DBI by default does a $dbh->ping first on connect (you
> can change the timing behavior.) Then it reconnects if the
> ping failed.
DBIC already handles that, too.
> If DBIC were o.k. with Apache::DBI, all that would be needed
> would be a class method to cause DBIC to do a DBI->connect.
> This method should be called at the start of a mod_perl handler
> request. Then let Apache::DBI ping the connection, and it will
> go connect it again if it's stale.
Plus the additional code to double-check Apache::DBI hasn't held onto a dbh
opened by another process or thread. Plus the additional code to double-check
there are no open $sths held by another piece of code that we'll accidentally
destroy by calling prepare_cached ($f_active parameter aside, careful
attention is still required to make prepare_cached usage safe, and DBIC's
solution came from a long e-mail conversation I had with Tim Bunce).
> But since Apache::DBI is useful, why not let DBIC ignore it and
> let it do its job? The responsibility would be on the mod_perl
> coder to know that the connection handle would be shared, and
> transactions as such would be touchy. (But if you need that
> kind of speed, you're probably using MyISAM anyway.)
If Apache::DBI were fork and thread-safe we would. c.f. the rest of the
thread, and a recent post on the Class::DBI list where code to attempt to
co-operate with Apache::DBI has been causing problems for somebody else.
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Dbix-class
mailing list