On Mon, 2006-05-08 at 17:23 +0200, Lionel MARTIN wrote: > I'm not sure this is right. Acording to what I read, and to my test, the > PerlInitHandler phase happens for every request, and not just when threads > are created.
I called it PerlInitHandle, but it's actually called PerlChildInitHandler. It's described here: http://perl.apache.org/docs/2.0/user/handlers/server.html#C_PerlChildInitHandler_ It does say that it only runs once per process. It should not run on every request. Despite the difference though, you're correct -- since it runs at the start of each process, not each thread, using connect_on_init() is probably not going to work with a threaded MPM. You should just call DBI->connect() from within your code instead. The first request in a new thread will take the hit of opening the connection. > The ideal would be to create the > connection when threads are started, create statement handles against this > connection, and keep all that until threads are killed. I'm not aware of a hook for the start of a thread. However, it's not a good idea to try to manage a cache of statement handles yourself. You should let DBI do this for you by using prepare_cached. That way, it will still work if your connection times out from inactivity and gets reconnected later. - Perrin