[prev in list] [next in list] [prev in thread] [next in thread] 

List:       apache-modperl
Subject:    Re: Forking and Database Handles
From:       Perrin Harkins <perrin () elem ! com>
Date:       2004-05-24 20:50:20
Message-ID: 1085431820.6569.108.camel () localhost ! localdomain
[Download RAW message or body]

On Mon, 2004-05-24 at 15:38, Matt Christian wrote:
> Because most of the errors I get are database-flavored, I'm thinking 
> that the issue has to do with sharing the database handle across the 
> fork.

Yes, in general you shouldn't do that.

> The DBI documentation says that setting InactiveDestroy on the 
> handle is the way to do that.

...for certain databases (not Oracle, for example), and all it does is
tell DESTROY not to close the connection.  That won't help with the
problem you'll have, which is multiple processes trying to use the same
connection.

> Indeed, when I test my code as a regular 
> cgi script without mod_perl I don't have these problems, so running 
> under mod_perl seems to be a contributing factor as well.

Are you using Apache::DBI?  That would keep the connection open in the
original process.  CGI will not do that.

Probably the safest approach would be to just open a new connection
after forking.  You can skip the cached Apache::DBI connections by using
the "dbi_connect_method => 'connect'" option when calling DBI->connect,
and get a fresh connection.

> Finally, one item that might be related is the use of CORE::exit(0). 
> The mod_perl "Performance Tuning" guide (and most other mod_perl 
> forking resources as well) advocate using this function. However the 
> mod_perl "Porting" guide says that CORE::exit should not be used 
> (because a "proper exit" does not happen) and that 
> Apache::exit(Apache::Constraints::DONE) or $r->child_terminate should 
> be used instead.

The porting guide is referring to the fact that calling CORE::exit
causes the current process to exit.  That isn't what you want normally
because you want the apache child process to continue and handle more
requests, but in a child process which you have forked from the apache
process you do want this behavior.  So, use CORE::exit for this.

- Perrin


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic