(Fwd) dbh handle in forked processes

(Fwd) dbh handle in forked processes

am 20.07.2006 07:44:31 von Tim.Bunce

----- Forwarded message from Gene Zhang -----

Date: Wed, 19 Jul 2006 14:47:53 -0700
From: Gene Zhang
To: tim.bunce@pobox.com
Subject: dbh handle in forked processes
DKIM-Signature: a=rsa-sha1; q=dns; l=618; t=1153345674; x=1154209674;
c=relaxed/simple; s=sjdkim7002; h=Content-Type:From:Subject:Content-Transfer-Encoding:MIME-V ersion;
d=cisco.com; i=genzhang@cisco.com; z=From:Gene=20Zhang=20
|Subject:dbh=20handle=20in=20forked=20processes;
X=v=3Dcisco.com; h=3DsD7xL/pn9TnBNQkdD6zrgC2K+Go=3D; b=CU2g8mhzDcuD8ZtwRrKWRFLn3lqy8vcCE+x7mbeK2yFOKJJi520TdFyxw9 /xo8zDN9IYDhyD
b19OICV/RztAqyyEZlJcK2ggl8ph4rHv/p7O/mSPfQ4YPR/ZnNV3+jeD;
Authentication-Results: sj-dkim-7.cisco.com; header.From=genzhang@cisco.com; dkim=pass (
sig from cisco.com verified; );

Hi mr. bunce,

I've an issue with programming DBI and could not find a solution in
either your DBI slideshow:
http://search.cpan.org/src/TIMB/DBI_AdvancedTalk_2004/index. htm
or your book ;
was hoping you could provide some guidance:

I have a program that establishes a $dbh, but then forks multiple child
processes, all of which use the same $dbh for queries and then terminate
(the process). I'd like to use the same $dbh connection handle for each
child process but as soon as one child exits, the handle is lost.

Is the best solution to use connect_cached?

-gene

----- End forwarded message -----

Re: (Fwd) dbh handle in forked processes

am 20.07.2006 09:09:40 von jonathan.leffler

------=_Part_6435_1315334.1153379380068
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 7/19/06, Tim Bunce wrote:
>
> ----- Forwarded message from Gene Zhang -----
>
> I've an issue with programming DBI and could not find a solution in
> either your DBI slideshow:
> http://search.cpan.org/src/TIMB/DBI_AdvancedTalk_2004/index. htm
> or your book ;
> was hoping you could provide some guidance:
>
> I have a program that establishes a $dbh, but then forks multiple child
> processes, all of which use the same $dbh for queries and then terminate
> (the process). I'd like to use the same $dbh connection handle for each
> child process but as soon as one child exits, the handle is lost.
>
> Is the best solution to use connect_cached?
>

No; the best solution is to connect in each child process. Anything else is
unreliable.

I'm pretty sure this is covered in 'perldoc DBI' - it certainly should be.



--
Jonathan Leffler #include
Guardian of DBD::Informix - v2005.02 - http://dbi.perl.org
"I don't suffer from insanity - I enjoy every minute of it."

------=_Part_6435_1315334.1153379380068--

Re: (Fwd) dbh handle in forked processes

am 20.07.2006 09:20:48 von Alexander

You may also want to look how Apache::DBI works.

Alexander

On 20.07.2006 09:09, Jonathan Leffler wrote:

> On 7/19/06, Tim Bunce wrote:
>
>>
>> ----- Forwarded message from Gene Zhang -----
>>
>> I've an issue with programming DBI and could not find a solution in
>> either your DBI slideshow:
>> http://search.cpan.org/src/TIMB/DBI_AdvancedTalk_2004/index. htm
>> or your book ;
>> was hoping you could provide some guidance:
>>
>> I have a program that establishes a $dbh, but then forks multiple child
>> processes, all of which use the same $dbh for queries and then terminate
>> (the process). I'd like to use the same $dbh connection handle for each
>> child process but as soon as one child exits, the handle is lost.
>>
>> Is the best solution to use connect_cached?
>>
>
> No; the best solution is to connect in each child process. Anything
> else is
> unreliable.
>
> I'm pretty sure this is covered in 'perldoc DBI' - it certainly should
> be.
>
>
>


--
Alexander Foken
mailto:alexander@foken.de http://www.foken.de/alexander/