Re: forking problem with dbd::mysql On 5/9/07, Jeremy Kister  wrote:
> On 5/9/2007 12:01 AM, Jeff Pang wrote:
> > 1) too less timeout setting in my.cnf? see /etc/my.cnf and look for this line:
>
> I actually have no my.cnf.  But if I s/my $pid = fork()/my $pid=1/ all
> works fine, even with 60 second sleeps.
>
> > 2) as we know,child exiting would return a SIGCHLD signal to parent,maybe this
> > break the dbh connection?try to add these 2 lines in parent code:
> >
> > use POSIX qw(:signal_h WNOHANG);
> > $SIG{CHLD}=sub {while((my $child=waitpid(-1,WNOHANG))>0){}};
>
> Nope, same problem.
>
> Thanks,
>
> --
>
> Jeremy Kister
> http://jeremy.kister.net./

It looks like it has something to do with $dbh going out of scope
(when the child exits).  You can see the behavior by first adding
"sleep 10;" to the child (the handle doesn't die for 10 seconds) and
then adding "$dbh = undef" to the child before the sleep (the handle
dies as soon as it is set to undef).  It is a hack, but so long as you
are using the AutoCommit attribute (on by default) you can also use
the mysql_auto_reconnect attribute.  Change


my $dbh = DBI->connect($dsn, $dbun, $dbpw, {RaiseError => 1});

to

my $dbh = DBI->connect(
    $dsn, $dbun, $dbpw,
    {
        RaiseError => 1,
        mysql_auto_reconnect => 1
    }
);

-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/


