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
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


Reply via email to