Randy Kobes wrote:
On Wed, 5 Jan 2005, Stas Bekman wrote:


Mike Carlton wrote:
[...]

But isn't there a problem with making db connections from startup.pl?
When the processes later fork, you potentially wind up with database
connection problems (I saw lots of problems under MP1 when I was doing
this).

Particularly with Class::DBI::mysql, just loading a class makes a
database connection.  Is there a safe way to make database connections
from startup.pl and not have it blow up?

Not if you use PerlChildInitHandler to open the actual connection, like Apache::DBI does: http://modperlbook.org/html/ch20_02.html


Hi Stas,
   It's probably just me, but just to clarify the wording -
are you saying the use of PerlChildInitHandler, as in
Apache::DBI, *is* a safe way to to initiate database
connections within a startup.pl?

Yes, because it does *not* initializes the connection at startup. It simply registers a handler that will be run at child_init. So each child process will have its own connection.


Also, does that depend on
whether one's using threads (assuming the underlying
database engine is thread safe). Thanks.

Frankly, I'm not sure what happens under threads. Apache::DBI doesn't implement CLONE, so it might be a problem.


FWIW, I'm planning to restart my work on DBI::Pool soon and then I'll know to tell more.

--
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Reply via email to