Hi Monks,
I have a web application running on Apache/mod_perl.
Each request sent to the application opens an Apache child process.
I have written a DBConnection class which connects to Oracle using DBI. I have implemented the class as a singleton so the same connection is used till the end of the request.
The problem is that it seems that the instance of the class is not dead when the request is done and the next request does not create a new instance but keeps using the first one.
Does it make sense? Do child processes share objects between them?
Here's my DBConnection class:
package DBConnection;
my $dbm;
#==========#
sub new {
#==========#
my($class, $name) = @_;
my $self = { name => $name };
bless($self, $class);
return $self;
}
#============#
sub instance
#============#
{
my ($class)= @_;
if(not defined $dbm)
{
$dbm = new DBConnection();
}
return $dbm;
}
#==========================#
sub getSingleConnection
#==========================#
{
my ($self) = @_;
unless($dbm->{dbh})
{
$dbm->{dbh} = $self->getConnection();
}
return $dbm->{dbh};
}
#==================#
sub getConnection
#==================#
{
my ($self) = @_;
my $dbh;
eval {
$dbh = DBI->connect('dbi:Oracle:host=dbserver;sid=db_sid;port=
+1521','user','passwrd');
or return undef;
};
warn $@ if $@;
return undef if $@;
return $dbh;
}
Thanks,
Asaf
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|