Todd Finney wrote:
> >Someone else said this would work but I believe they are
> >incorrect. Your
> >startup file (presumably loaded via PerlRequire startup.pl) will be
> >executed in the parent Apache process _before_
> >forking. Unfortunately,
> >DBI database handles become invalid after a fork.
> You presumably mean 'statement handles' there. Doing a connect_on_init
> via startup.pl is standard operating procedure, and it works just
> fine. But you know that.
It may be a standard operating procedure, but it cannot work
with DBD::mysql. The precise statement is:
- A created database handle may be shared by different
threads and/or processes,
but *only* if they serialize using the database handle.
Serialization can be done, for example, if Apache is using
threads. With fork() serialization is *very* hard.
Also, if one thread/process closes the database handle,
the others cannot use the handle anymore.
- The same holds true for a statement handle.
> Am I reading that incorrectly?
I don't know this page, but I assume that it recommends
using placeholders, which is not only good style, but
indeed recommendable in terms of performance.
If this page recommends sharing statement handles, I strongly
discourage this, considering the above.
In the case of DBD::mysql, it is possible to share an *inactive*
statement handle: An inactive statement handle is a handle,
where you either did not do an execute() upon or where you
did a finish() or you have read all the result rows.
However, this may *very* easily change in the future: The
above works, because the driver DBD::mysql emulates placeholders.
As soon as the MySQL client library supports them, the
above statement will almost definitely break.