You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jordan McLain <jo...@gmail.com> on 2006/10/11 04:57:48 UTC

DESTROY

I have written a handler that calls a constructor to a module that I
have written.  I do not believe that the subsequent destructor is
being called unless I explicitly call it.  Is this a feature of
mod_perl?  I would think that every time an instance of the module is
created, it would be destroyed properly when using mod_perl.

The reason I am doing this, is that I am testing to see if I want to
continue using Apache::DBI.  I have 4 databases that need to be
connected to, and I end up having alot of MySQL threads hanging out if
I use Apache::DBI.  The problem comes in that I have all disconnects
in the DESTROY method for the module(all of my database interaction is
abstracted using an OO module) and I end up having no difference
between Apache::DBI and using only DBI (threads stay persistent)
unless I call destroy explicitly from the handler ( $db->DESTROY ).

sub DESTROY {
        my $self = shift;

        $self->dbh->disconnect() if defined $self->dbh;
}

Re: DESTROY

Posted by "Dondi M. Stroma" <ds...@verizon.net>.
I am not sure, but I think the problem you have is that Apache::DBI ignores 
any disconnect() calls on database handles, and doesn't actually disconnect.

----- Original Message ----- 
From: "Jordan McLain" <jo...@gmail.com>
To: <mo...@perl.apache.org>
Sent: Tuesday, October 10, 2006 10:57 PM
Subject: DESTROY


>I have written a handler that calls a constructor to a module that I
> have written.  I do not believe that the subsequent destructor is
> being called unless I explicitly call it.  Is this a feature of
> mod_perl?  I would think that every time an instance of the module is
> created, it would be destroyed properly when using mod_perl.
>
> The reason I am doing this, is that I am testing to see if I want to
> continue using Apache::DBI.  I have 4 databases that need to be
> connected to, and I end up having alot of MySQL threads hanging out if
> I use Apache::DBI.  The problem comes in that I have all disconnects
> in the DESTROY method for the module(all of my database interaction is
> abstracted using an OO module) and I end up having no difference
> between Apache::DBI and using only DBI (threads stay persistent)
> unless I call destroy explicitly from the handler ( $db->DESTROY ).
>
> sub DESTROY {
>        my $self = shift;
>
>        $self->dbh->disconnect() if defined $self->dbh;
> } 


Re: Re: DESTROY

Posted by Jordan McLain <jo...@gmail.com>.
Good call, thanks for the help guys.  I really appreciate it.

Jordan

On 10/11/06, Philip M. Gollucci <pg...@p6m7g8.com> wrote:
> Dondi M. Stroma wrote:
> > I believe that since $db is a global variable it's not going to be
> > destroyed.  If you got rid of the 'use vars' and changed it to
> >
> > sub handler {
> >  my $r = shift;
> >  my $db = eCarList::DB->new();
> >  ...
> > }
> >
> > then it would be.
> This is absolutely the correct change.
>
> --
> ------------------------------------------------------------------------
> Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
> Consultant / http://p6m7g8.net/Resume/resume.shtml
> Senior Software Engineer - TicketMaster - http://ticketmaster.com
> 1024D/A79997FA F357 0FDD 2301 6296 690F  6A47 D55A 7172 A799 97F
>
> When I call your name, Girl, it starts to flame
> Burning in my heart, Tearing it all apart..
> No matter how I try My love I cannot hide....
>

Re: DESTROY

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Dondi M. Stroma wrote:
> I believe that since $db is a global variable it's not going to be 
> destroyed.  If you got rid of the 'use vars' and changed it to
> 
> sub handler {
>  my $r = shift;
>  my $db = eCarList::DB->new();
>  ...
> }
> 
> then it would be.
This is absolutely the correct change.

-- 
------------------------------------------------------------------------
Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Software Engineer - TicketMaster - http://ticketmaster.com
1024D/A79997FA F357 0FDD 2301 6296 690F  6A47 D55A 7172 A799 97F

When I call your name, Girl, it starts to flame
Burning in my heart, Tearing it all apart..
No matter how I try My love I cannot hide....

Re: Re: DESTROY

Posted by "Dondi M. Stroma" <ds...@verizon.net>.
I believe that since $db is a global variable it's not going to be 
destroyed.  If you got rid of the 'use vars' and changed it to

sub handler {
  my $r = shift;
  my $db = eCarList::DB->new();
  ...
}

then it would be.

----- Original Message ----- 
From: "Jordan McLain" <jo...@gmail.com>
To: <mo...@perl.apache.org>
Sent: Wednesday, October 11, 2006 12:06 PM
Subject: Re: Re: DESTROY


>I have the call to the module in a block already.
>
> It goes something like:
>
> package eCarList::Admin;
> use eCarList::DB;
> use eCarList::Output;
>
> use vars qw($db);
>
> sub handler {
>      my $r = shift;
>
>      $db = eCarList::DB->new();
>
>      ....
> }
>
> On 10/11/06, Tyler Bird <bi...@epromo.com> wrote:
>> Try wrapping your calls to your module in a function because an object
>> is cleaned up at the end of a block.
>>
>> -- yourscript.pl --
>>
>> sub main()
>> {
>>     my $db = Apache::DBI->new();
>>
>>
>> } # at the end the object refrenced by $apache_dbi will have it's
>> destroy method called
>>
>> I think you have have done somehting like this
>>
>> #!/usr/bin/perl
>>
>> my $db = Apache::DBI->new()
>>
>>
>>
>> In that case I don't think it's ever destroyed.
>>
>>
>> but other thoughts I have are that whenever you use mod_perl with
>> apache::dbi it uses persistent database connections
>> and does not close them when you call disconnect.
>>
>> But I know you should be able to write it to get the destructor to be 
>> called
>>
>>
>> Jordan McLain wrote:
>> > I have written a handler that calls a constructor to a module that I
>> > have written.  I do not believe that the subsequent destructor is
>> > being called unless I explicitly call it.  Is this a feature of
>> > mod_perl?  I would think that every time an instance of the module is
>> > created, it would be destroyed properly when using mod_perl.
>> >
>> > The reason I am doing this, is that I am testing to see if I want to
>> > continue using Apache::DBI.  I have 4 databases that need to be
>> > connected to, and I end up having alot of MySQL threads hanging out if
>> > I use Apache::DBI.  The problem comes in that I have all disconnects
>> > in the DESTROY method for the module(all of my database interaction is
>> > abstracted using an OO module) and I end up having no difference
>> > between Apache::DBI and using only DBI (threads stay persistent)
>> > unless I call destroy explicitly from the handler ( $db->DESTROY ).
>> >
>> > sub DESTROY {
>> >        my $self = shift;
>> >
>> >        $self->dbh->disconnect() if defined $self->dbh;
>> > }
>> >
>>
>> 


Re: Re: DESTROY

Posted by Jordan McLain <jo...@gmail.com>.
I have the call to the module in a block already.

It goes something like:

package eCarList::Admin;
use eCarList::DB;
use eCarList::Output;

use vars qw($db);

sub handler {
      my $r = shift;

      $db = eCarList::DB->new();

      ....
}

On 10/11/06, Tyler Bird <bi...@epromo.com> wrote:
> Try wrapping your calls to your module in a function because an object
> is cleaned up at the end of a block.
>
> -- yourscript.pl --
>
> sub main()
> {
>     my $db = Apache::DBI->new();
>
>
> } # at the end the object refrenced by $apache_dbi will have it's
> destroy method called
>
> I think you have have done somehting like this
>
> #!/usr/bin/perl
>
> my $db = Apache::DBI->new()
>
>
>
> In that case I don't think it's ever destroyed.
>
>
> but other thoughts I have are that whenever you use mod_perl with
> apache::dbi it uses persistent database connections
> and does not close them when you call disconnect.
>
> But I know you should be able to write it to get the destructor to be called
>
>
> Jordan McLain wrote:
> > I have written a handler that calls a constructor to a module that I
> > have written.  I do not believe that the subsequent destructor is
> > being called unless I explicitly call it.  Is this a feature of
> > mod_perl?  I would think that every time an instance of the module is
> > created, it would be destroyed properly when using mod_perl.
> >
> > The reason I am doing this, is that I am testing to see if I want to
> > continue using Apache::DBI.  I have 4 databases that need to be
> > connected to, and I end up having alot of MySQL threads hanging out if
> > I use Apache::DBI.  The problem comes in that I have all disconnects
> > in the DESTROY method for the module(all of my database interaction is
> > abstracted using an OO module) and I end up having no difference
> > between Apache::DBI and using only DBI (threads stay persistent)
> > unless I call destroy explicitly from the handler ( $db->DESTROY ).
> >
> > sub DESTROY {
> >        my $self = shift;
> >
> >        $self->dbh->disconnect() if defined $self->dbh;
> > }
> >
>
>