ibm1620 has asked for the wisdom of the Perl Monks concerning the following question:
I have a parent process that creates a DBI::mysql connection (held in $dbh) to database D, executes some SQL requests, forks some children, (each of which want to execute SQL requests to the same database), and then continues to execute more SQL. The children of course inherit $dbh, but I'm not having much luck from then on.
Someone suggested executing $dbh->{InactiveDestroy} = 1; before forking, to prevent the children's exits from clobbering the shared connection. But I get from Sharing a database handle over multiple processes (dated 2001) that you shouldn't expect a database handle to survive the fork.
So what approach should I take? It sounds like I should disconnect $dbh before I fork (so that no children inherit my connection); have the children each connect afresh; and, back in the parent, *reconnect* to D and continue running.
Or perhaps I should leave the connection open, issue $dbh->{InactiveDestroy} = 1; before any forking, and have the children simply create their own connections in $dbh_child. When they exit, the $dbh_child connection will be cleaned up, and the inherited $dbh connection will be untouched.
Thanks for any help!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sharing a database connection across fork()
by Anonymous Monk on Sep 11, 2014 at 09:03 UTC | |
by ibm1620 (Hermit) on Sep 12, 2014 at 19:28 UTC | |
by wrog (Friar) on Sep 13, 2014 at 01:08 UTC | |
by ibm1620 (Hermit) on Sep 15, 2014 at 23:29 UTC | |
|
Re: Sharing a database connection across fork()
by wrog (Friar) on Sep 11, 2014 at 14:31 UTC | |
|
Re: Sharing a database connection across fork()
by locked_user sundialsvc4 (Abbot) on Sep 11, 2014 at 12:38 UTC |