Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Can processes share a DBI connection?

by jecouto (Initiate)
on Jul 10, 2002 at 07:04 UTC ( [id://180695]=perlquestion: print w/replies, xml ) Need Help??

jecouto has asked for the wisdom of the Perl Monks concerning the following question: (database programming)

Is it safe to open a connection to a database and then use that same connection in all the children your process forks? Or is it necessary to open a connection for each child?

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: Can process share a DBI connection?
by Zaxo (Archbishop) on Jul 10, 2002 at 07:24 UTC

    Each process should open its own DBI connection. Processes will readily share one if it's opened before fork, but that has bad side effects, and no good ones that I know of. Two processes talking over one connection may get a db server confused, and the first process to end will take the serverside connection down, with no notification to the surviving process. Further confusion may result when the survivor tries to close its copy.

    Moral - Don't call &DBI::connect before a fork, even if one process never uses the connection.

Re: Can process share a DBI connection?
by grantm (Parson) on Jul 10, 2002 at 11:33 UTC
    I agree with Zaxo - don't do it. If you have a need to multiplex multiple processes into one DBI connection, you might want to investigate DBI::ProxyServer
Re: Can process share a DBI connection?
by pajout (Curate) on Oct 12, 2005 at 09:06 UTC
    I agree with previous answers. If problem is many opened connections, think about Apache::DBI (if forked processes are httpd's :) ) or about SQL Relay, which is daemon realizing connection pooling against various DB engines.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://180695]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-19 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found