On 5/9/07, Jeff Pang <[EMAIL PROTECTED]> wrote:
snip
Using InactiveDestroy flag seems a standard way since this module's author 
provide this flag.
But it's maybe bring some problems when the applications are large enough,and 
it's not
the fact that every programmer would disconnect their dbh connections in 
time.For
example,consider the case programs were run under modperl and without 
Apache::DBI,
using this flag would possibly make lots of db connections to database and 
consume db's
socket source quickly.

Then for me I would maybe consider another way of creating its own dbh in child 
after fork.
Hope I'm right,:)

The only place InactiveDestroy is appropriate is just after a fork in
either the parent or the child (depending on which one is keeping the
handle).  You should immediately disconnect the database handle after
setting the flag (either explicitly with disconnect or implicitly by
opening another and assigning it to the same scalar).  In the case of
the code in question it looks like this

               my $pid = fork();
               if ($pid == 0 && defined($pid)){
                       # child connection
                       # do lots of stuff in here, including make our
own db connection
                       $dbh->{InactiveDestroy} = 1;
                       $dbh = DBI->connect($dsn, $dbun, $dbpw,
{RaiseError => 1});
                       # do stuff
                       exit;
               } elsif ($pid) {
                       # this is the parent - do nothing
               } else {
                       warn "unable to fork: resources unavailable.\n";
               }

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to