in reply to Access the same database in two processes
I don't recommend sharing the database handle like that. Think about it, if two sets of instructions are going through the same handle, which one gets to go first? Would they even be valid instructions?
One thing to note is, even if you don't share the same database connection between the parent and the child, you need to be careful of the self-clean up that the database drivers perform :
my $parent_dbh = DBI->connect( ... ); if( my $pid = fork() ) { # do stuff... # >>> $parent_dbh may be cleaned up here, # >>> because it *is* in the child's scope exit 0; }
You could do this:
# fork first if( my $pid = fork() ) { # do stuff, including opening new DBI connection exit 0; } my $parent_dbh = DBI->connect(...); # do parent stuff
or, if you *really* need to open the connection in the parent beforehand,
my $parent_dbh = DBI->connect(...); $parent_dbh->{ InactiveDestroy } = 0; if(my $pid = fork()) { # do stuff }
Incidentally, setting InactiveDestroy may actually fix your problem, but I still would STRONGLY advise you not to share the same handle between the parent and the child
|
|---|