I think you can do it on startup just not startup of the parent httpd process.
What you can do is use a PerlChildInitHandler (the name may have changed in mod_perl2, sorry I'm too lazy to check). This is a hook into the part of the httpd lifecycle that gets executed when the _child_ process starts up. Doing your connection here will give you a warm connection before that child serves a page (hence first hit is not slow) but still ensures no sharing of handles between child processes and the issue you're having. Why not give that a go. I'm sure this was documented somewhere a few years ago, if you nag me I'll have a go at finding the origianl document/article. > -----Original Message----- > From: Helmut Zeilinger [mailto:[EMAIL PROTECTED] > Sent: 29 March 2007 16:28 > To: Jonathan Vanasco > Cc: modperl@perl.apache.org > Subject: Re: Apache::DBI (another) question > > I see, i will change my strategy towards > avoiding the conncetion on startup. > > Thank you! > > Helmut > > Jonathan Vanasco schrieb: > > > > On Mar 29, 2007, at 7:46 AM, Helmut Zeilinger wrote: > > > >> $self->{'dbh'} = DBI->connect ("DBI:mysql:somedb:localhost", > >> "root", "", {RaiseError => 1}); > > connecting as root? > >> > >> While running the server there is only one apache - mysql > connection > >> visible via > >> "mysqladmin processlist" and not one connection for each > apache child > >> process > >> as usually. > >> > >> I have found no irregularities, but this statement in the > Apache::DBI > >> manpage makes me > >> worried: > >> > >> "...Also it is not possible to create a database handle > upon startup > >> of the httpd and then inheriting this handle to every subsequent > >> server. This will > >> cause clashes when the handle is used by two processes at the same > >> time. .." > > > > Thats the wrong way to do things. You should expect to have every > > kind of problem imaginable. > > You're starting the persistent connection in the 'main' server, and > > sharing it with the children. > > > > If you need to connect on startup to pull configuration vars: > > a- connect before using Apache::DBI - not entirely > necessary, but > > can avoid edge cases. > > b- connect using an alternate connection string > > 'user=myapp.config' - not entirely necessary, but can > avoid edge cases. > > c- make sure you destroy the connection before init - entirely > > necessary > > > > in your modperl code, use Apache::DBI->connect_on_init( > %kw_args ) to > > queue the database connect ( or make your first connection in code > > that is only executed when a page is requested ). > > That will give you 1 connection per child, which is local to that > > child and persists throughout the life of the child. > > > > last_insert_id will not work reliably in that situation, > and neither > > will transactions. all connections are using the same db handle, > > > > > > // Jonathan Vanasco > > > > | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > - - - - - > > - - - - - - - - - - - - - - - - - - - > > | SyndiClick.com > > | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > - - - - - > > - - - - - - - - - - - - - - - - - - - > > | FindMeOn.com - The cure for Multiple Web Personality Disorder > > | Web Identity Management and 3D Social Networking > > | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > - - - - - > > - - - - - - - - - - - - - - - - - - - > > | RoadSound.com - Tools For Bands, Stuff For Fans > > | Collaborative Online Management And Syndication Tools > > | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > - - - - - > > - - - - - - - - - - - - - - - - - - - > > > > > > > ------------------------------------------------------------------------ For more information about Barclays Capital, please visit our web site at http://www.barcap.com. Internet communications are not secure and therefore the Barclays Group does not accept legal responsibility for the contents of this message. Although the Barclays Group operates anti-virus programmes, it does not accept responsibility for any damage whatsoever that is caused by viruses being passed. Any views or opinions presented are solely those of the author and do not necessarily represent those of the Barclays Group. Replies to this email may be monitored by the Barclays Group for operational or business reasons. ------------------------------------------------------------------------