Eric Kolve wrote:

> Is it possible to share a database handle initialized in a parent with
> forked children ?  What I want to do is process a file which needs to
> execute many SELECT statements in parallel.  I am wondering if each
> child needs to instantiate its own dbh or whether you can execute sql
> simultaneously against the same dbh.

As Matthew Persico said, it is not safe to create a $dbh, fork children,
and then have any of the children try to access the database via the
pre-created $dbh.

What Matthew didn't mention is that the documentation says that this is
the case -- see the Cheetah book.  ...time passes...  I went to get a page
reference, and I'm not sure that I came up with a good one: p204
(InactiveDestroy) discusses it a bit indirectly.

Tim -- suggestion for a future edition of book/DBI specification: it
should be explicitly called out that using a $dbh across even a single
fork() may not work at all, even if the parent does not attempt to use the
handle, let alone attempting to use it across multiple fork.

And, as a specific f'r'instance, DBD::Informix will not work reliably if
you try that -- the connection is associated with a specific PID and the
children have the wrong PID (process ID).

--
Jonathan Leffler ([EMAIL PROTECTED], [EMAIL PROTECTED])
Guardian of DBD::Informix 1.00.PC1 -- see http://www.cpan.org/
#include <disclaimer.h>


Reply via email to