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!
In reply to Sharing a database connection across fork() by ibm1620
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |