.--- On Tue, 14 Mar 2006, Badai Aqrandista wrote:
| I am having problem with database connection for the session locks dropping
| intermittently...
`---

Apache::DBI will solve this for you, and also provide other
benefits. Not only can it automatically provide reconnection on fail,
it'll reuse connections if the connect params are the same (one
connection per child in the pre-fork model).

This functionality is transparent -- just load it up, and the magic
happens. The only caveat is that you must be sure to load it before
DBI, or anything else that uses DBI. The best place for this is in
your site init script. In the configuration for your vhost in apache,
you might have, for example:

    PerlRequire /srv/www/vhost/my.site.com/etc/init.pl

init.pl should contain very little -- just enough to get things
loaded that you'll use later on. Mine contains only:

    use Apache::Cookie      ();
    use Apache::DBI         ();
    use DBI                 ();
    use DBD::Oracle         ();             # for ORA_RSET
    use Digest::SHA1        ();
    use Mail::Send          ();
    use Time::HiRes         ();

    1;                                      # you must return a true value


Note that I don't actually import anything. I just get the modules
loaded up. Individual components who later use these modules are
responsible for importing what they need, but it speeds up the loads
by getting mod_perl loaded up. (If you just load Perl modules in once
blocks, you'll have many copies of the module loaded in various
components' namespaces.) In my init.pl, Apache::DBI is loaded before
DBI, and that's the secret.

In my current setup, I use a separate component to connect to the
DB. This is called from my master handler, from which my top-level
autohandler inherits. If the connect component cannot connect, it
throws an exception which the master handler catches, and an error
page is delivered instead. On the other hand, if the connector is
successful, it returns a database handle, which I store into a
local()ly scoped Mason global that allows other components to use it
without it being passed around laboriously. 

This is more Mason native, but it may not be the right solution for
everyone. Let me know if you would like me to provide this solution to
you, and I'll deliver.

        Best regards,

        -- Patrick

--
.------ Patrick M. Jordan ------.  Random unused band name:
| Systems/Network Administrator |  Will Robinson and the Dangers
`----- Antistatic Matrix -------'



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to