Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

From all the doc I can find DBI::clone() should create a duplicate of the established connection by using the same information originally used to connect. I have a process that forks of child processes and I want each one to have their own connection to the DB.

The problem is that the clone() gives all the child processes the same handle. I was under the assumption that the code for the child process would not be executed until after the fork, if this is so then each child should get a unique connection. Can someone explain why each child proc has the same handle?

Here is what I get when I run the code below:

Parent db handle is DBI::db=HASH(0x7381e8) I'm child 6302 with db handle DBI::db=HASH(0x74fc2c) I'm child 6303 with db handle DBI::db=HASH(0x74fc2c) I'm child 6304 with db handle DBI::db=HASH(0x74fc2c) I'm child 6305 with db handle DBI::db=HASH(0x74fc2c) I'm child 6306 with db handle DBI::db=HASH(0x74fc2c) I'm child 6308 with db handle DBI::db=HASH(0x74fc2c) I'm child 6307 with db handle DBI::db=HASH(0x74fc2c) I'm child 6310 with db handle DBI::db=HASH(0x74fc2c) I'm child 6309 with db handle DBI::db=HASH(0x74fc2c)
snip...
for (my $counter = 1;$counter < $MAXCHILDREN;$counter++) { if (my $pid = fork) { # in parent, do nothing } elsif (! defined $pid) { print "fork failed! -->$!\n"; exit; } else { my $new_dbh = $dbh->clone(); print "I'm child $$\n\twith db handle $new_dbh\n"; exit; } }
...snip

In reply to Using DBI::clone() by gnu@perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-20 10:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found