logo       

Re: Same $dbh under different pids?: msg#00594

apache.mod-perl

Subject: Re: Same $dbh under different pids?

On Tue, Oct 29, 2002 at 09:06:45PM +0000, Richard Clarke wrote:
> >Moi,
> >
> >a quick question: is it possible to have the 'same' dbh across the apache
> >children even if you do your best not to?
> >
> >This minimalistic handler:
> >use strict;
> >package Foo;
> >use Apache::DBI;
> >use DBI;
> >use Apache::Constants qw':common';
> >
> >my $dbh;
> >
> You haven't initialised this, so each request will get the same object
> that is made below.
>
> >$Apache::DBI::DEBUG = 1;
> >
> This should be in a start up file really.
>
> >
> >sub handler {
> > my $r = shift;
> > $r->send_http_header;
> > $r->print("ok");
> >
> You could just put,
> print "ok";
>
> > $dbh ||= DBI->connect("dbi:mysql: ... etc);
> >
> Apache::DBI takes care of pooling connections.
> Use,
>
> my $dbh = DBI->connect(@CONNECT);
>
> and get rid of the global $dbh above.

Richard,

thanks for your suggestions. The problem is not so much in the code (I know
the code above isn`t the 'best' way) but in the fact I seem to get the same
$dbh across children. I`m just curious if that is to be expected:

okdbh: Apache::DBI::db=HASH(0x8269a7c) (85799)
okdbh: Apache::DBI::db=HASH(0x8269a7c) (85800)
okdbh: Apache::DBI::db=HASH(0x8269a7c) (85801)
okdbh: Apache::DBI::db=HASH(0x8269a7c) (85802)
okdbh: Apache::DBI::db=HASH(0x8269a7c) (85803)
okdbh: Apache::DBI::db=HASH(0x8261424) (85799)
okdbh: Apache::DBI::db=HASH(0x8261424) (85800)

(Each line is a reload with the code after your suggestions)

Thanks,
Harmen

--
The Moon is Waning Crescent (37% of Full)



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise