>>> PH> Don't open a connection during startup.
>>> PH> Open a connection in the child process instead.
>> 
> BT > I will second this. I've done this (unintentionally) when using MySQL,
> and
> BT > you get a lot of weird errors about statement handles being active, etc.
> 
> I haven't read the entire thread, so forgive me if I'm restating. But there
> are reasons for sharing DB connections (and reasons not to). In the case of
> MySQL and getting messages about active statement handles, that's because
> you're disconnecting the DBH. If you are in a shared connection enviroment
> with MySQL, you are winning. Since you don't have to worry about things like
> transactions and rolling back somebody elses changes. All you need to do is
> finish() your statement handled when you are finished with them:
> 
> $sth->finish;
> 
> This will prevent the errors you are seeing and will allow you to keep the
> shared DB connection. A shared connection is usefull for efficiency, since
> creating a connection may be expensive.

No, I called finish on all of my statement handles; that is not the reason
for the errors I got. The behavior I am talking about *only occurs* for me
when I open a connection in the Apache parent. Then this same DB connection
is shared across all of the Apache children, and Strange Things occur.

>> I am sorry but this topic is confusing me... Are you saying that
>> persistent DB connection objects are bad?
> 
> It sounds like that, doesn't it?

Well, I'm sorry if it sounds like that, but that's not what I'm saying. :)

I am merely echoing Perrin's statement that opening a shared connection in
the parent is bad, because this connection is then shared between *all* of
the children. You don't want this. You want one connection per child, not
one connection shared between all Apache children. The latter *will* cause
problems.

>> I am about to switch to Apache::DBI for that very reason. I don't
>> want to create a new db handle with every request. Should I stop,
>> or am I missing something here?
> 
> Nope, you've got it. If you don't have transactions (anything else?) to worry
> about, I'd say to use Apache::DBI.

I would absolutely encourage anyone to use Apache::DBI.

The case I am talking about is a very particular one: when you open a shared
connection in the parent. You don't want this connection to be an
Apache::DBI connection, so instead you should use the magic 6th arg to
DBI::connect to force DBI to handle it exclusively.

bye,
Ben

Reply via email to