[Israel.pm] Weird problem with DB connection & forking...

Yuval Yaari yuval at windax.com
Tue May 18 05:12:57 PDT 2004


Alright... There's something I just can't explain nor understand - so 
please help me out.

I wrote a server which is running for a long time now. I was asked to 
move it to a different, newer machine.
The newer machine has the latest DBI and DBD::mysql and runs perl 5.8.1.
The older one has older DBI and DBD::mysql [see below] and perl 5.8.0.
I'm not sure it can cause the problem but the newer server has a newer 
MySQL installation.

The server opens a database connection using DBI, and only then (if the 
BACKGROUND constant is true) forks and exits [just a small hack...].

This really worked well on the old machine but on the new machine it 
says "DBD::mysql::db selectrow_array failed: MySQL server has gone away 
at..." when I try to selectrow_array.
I copied the relevant lines to another file and ran it, and it worked well.
I then set the BACKGROUND constant to 0 so I could trace everything 
easily (throw errors to STDIN/STDERR instead of into files) - and it worked.
So I figured it's the fork line, moved the my $dbh = DBI....... line 
AFTER the fork, and it works!

But even though it works, I want to understand what caused the problem...

OK, the details:

# The forking part - a simple trick to put my server "in the background"...
if (BACKGROUND) {
        fork and exit;
}

On the new machine:
# perl -v
This is perl, v5.8.1 built for i586-linux-thread-multi
# perl -MDBI -le 'print $DBI::VERSION'
1.42
# perl -MDBD::mysql -le 'print $DBD::mysql::VERSION'
2.9003

On the old machine:
perl -v
This is perl, v5.8.0 built for i386-linux-thread-multi
# perl -MDBI -le 'print $DBI::VERSION'
1.30
# perl -MDBD::mysql -le 'print $DBD::mysql::VERSION'
2.1017


  Thanks,
  --Yuval




More information about the Perl mailing list