Greetings,
I've recently encoutered problems using Class::DBI under mod_perl 2 environment (win32). As long as there is more than one response handler which uses CDBI objects, apache throws this error:
[Wed May 02 18:55:09 2007] [error] [client 127.0.0.1] DBD::mysql::db F
+ETCH failed: handle 2 is owned by thread 161929c not current thread 1
+ba79ec (handles can't be shared between threads and your driver may n
+eed a CLONE method added) at c:/Perl/site/lib/Apache/DBI.pm line 226.
+\n
I have then googled for a possible workaround and found this patch to Ima::DBI :
sub _mk_db_closure {
my ($class, $dsn, $user, $pass, $attr) = @_;
$attr ||= {};
my $dbh;
my $process_id = $$;
return sub {
# set the PID in a private cache key to prevent us
# from sharing one with the parent after fork. This
# is better than disconnecting the existing $dbh since
# the parent may still need the connection open. Note
# that forking code also needs to set InactiveDestroy
# on all open handles in the child or the connection
# will be broken during DESTROY.
$attr->{private_cache_key_pid} = $$;
# reopen if this is a new process or if the connection
# is bad
if ($process_id != $$ or not ($dbh && $dbh->FETCH('Active') &&
+ $dbh->ping)) {
$dbh = DBI->connect_cached($dsn, $user, $pass, $attr);
$process_id = $$;
}
return $dbh;
};
}
Which leads to the same result. Perhaps it is because all threads share the same process id?
Then I've found another solution
here, but I failed to undestand how to use it! The problem is that I don't know how to get current request object inside db_Main. Because Apache->request (class method; which used in the solution) is something I can't find under Apache2.
The way I usually get the request object is I'm grabbing it, when it is passed to the response handler and then passing it further if needed or store it as an object member.
But I'd like to keep my model classes and underlying data mapping classes away from any references to request object. Perhaps there is a way just to get the request object for the current context, which would suit perfectly.
Or perhaps I'm missing something obvious again ;)
May be there is another way to deal with cdbi under mod_perl? Or another way for objects mapping?
Thanx,
Artem.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.