Re: Error: handles can't be shared between threads

[prev] [thread] [next] [Date index for 2005/05/20]

From: Octavian Rasnita
Subject: Re: Error: handles can't be shared between threads
Date: 20:27 on 20 May 2005
Hi,

From: "Perrin Harkins" <perrin@xxxxxxxxx.xxx>
> > I have put the following lines in a startup.pl file which is included
for
> > all virtualhosts (but I have a single virtual host):
> >
> > use Apache::DBI ();
> > Apache::DBI->connect_on_init('DBI:mysql:database=test', 'root', undef,
> > {PrintError => 1, RaiseError => 0, AutoCommit => 1});
> >
> > Then I have called the modules that use DBI in a second "preload.pl"
program
> > which is included just in my virtual host, using:
> >
> > use Site::Module1 ();
> > use Site::Module2 ();
>
> What's going on in there?  Are you using Class::DBI, by any chance?
>

No, I have never used Class::DBI in any module.

> > I have noticed that if I comment out the lines from the second file, the
> > site works fine, but I am not sure if I won't have problems after a
certain
> > time.
> > It seems that I am not allowed to launch the modules at server startup.
>
> It just means that those modules open database handles when you load
> them and cache those handles in globals or closures.  That will always
> cause problems.  You need to make them postpone opening the handles, or
> stop keeping cached copies of the handles.
>

Ok, it seems that I am closer to find the problem.
I could postpone opening them by not loading them at server startup, but I
think a better idea would be to stop keeping cached copies of the handles.
However, I have no idea how to do that.

In all the modules I have put something like:

package Site::Module1;

use strict;
use Site::MySQL (); #The module that connects to MySQL
my $dbh = Site::MySQL::dbh();

#Then the subroutines follow... and they use the $dbh.

What should I do?

Put "use Site::MySQL" and "my $dbh = Site::MySQL::dbh()" inside of
subroutines?
Close the database connection after each request using $dbh->disconnect() or
$dbh->close() or other way?

Thank you.

Teddy

Error: handles can't be shared between threads
Octavian Rasnita 17:47 on 19 May 2005

Re: Error: handles can't be shared between threads
Perrin Harkins 20:48 on 19 May 2005

Re: Error: handles can't be shared between threads
Octavian Rasnita 01:32 on 20 May 2005

Re: Error: handles can't be shared between threads
Perrin Harkins 03:50 on 20 May 2005

Re: Error: handles can't be shared between threads
Octavian Rasnita 20:27 on 20 May 2005

Re: Error: handles can't be shared between threads
Perrin Harkins 20:45 on 20 May 2005

Generated at 15:53 on 25 May 2005 by mariachi v0.52