Benjamin Trott wrote:
>
> > PH> Don't open a connection during startup. If you do, it will be shared when
> > PH> Apache forks, and sharing a database handle is bad for the same reasons
> > PH> sharig a file handle is. Open a connection in the child process instead.
>
> I will second this. I've done this (unintentionally) when using MySQL, and
> you get a lot of weird errors about statement handles being active, etc.
>
> > Speaking of which, what does one do when Apache::DBI is loaded, and
> > the parent process needs to pull some config info out of the database
> > that all clients also use? That is, how can I force Apache::DBI to
> > close that handle prior to the forking of children?
>
> By using the magic 6th arg ($connect_meth in the DBI::connect source) to
> DBI::connect. In my DB wrapper I have a connect method that internally calls
> DBI::connect; before doing so, it checks to see if it is being called while
> Apache is starting up in the parent process, and if so, it uses this special
> arg.
>
> my @args = ("dbi:$db->{driver}:$dbname", $user, $pass,
> { RaiseError => 1 });
> push @args, (undef, 'connect')
> if $Apache::Server::Starting or $Visius::httpd_conf::Loading;
>
> $self->{handle} = DBI->connect(@args);
>
> The 'connect' is that magic argument that forces DBI to use its standard
> connect method, rather than Apache::DBI::connect, when creating the new db
> handle. This means that it is essentially a use-once DB handle, and that it
> will not be reused by Apache::DBI.
>
> Does this help?
>
> bye,
> Ben
I am sorry but this topic is confusing me... Are you saying that
persistent DB connection objects are bad? 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?
RFC
-r