Guess it just caught me off guard. I have been able to place reference to objects and such wihtout trouble. What part of DBH makes it special?
-----Original Message----- From: Steve Sapovits [mailto:[EMAIL PROTECTED]] Sent: Wednesday, September 25, 2002 3:32 PM To: [EMAIL PROTECTED]; DBI Mailing List Subject: RE: Sharing a DBH via IPC::Shareable. You need to read up on shared memory. You can't share pointers between processes and expect them to have any meaning -- they're addresses from the memory space of the creating process. You can put them in the shared memory segment. But they'll just refer to meaningless memory addresses in another process. ---- Steve Sapovits GSI Commerce [EMAIL PROTECTED] > -----Original Message----- > From: James Maes [SMTP:[EMAIL PROTECTED]] > Sent: Wednesday, September 25, 2002 3:01 PM > To: DBI Mailing List > Subject: Sharing a DBH via IPC::Shareable. > > Hey all, got a problem here which I don't quite understand. I need to > share a pool of dbi connections between N perl processes. I know that > only > one process may use a DBH at at time, and can handle that. The problem > that > I am having can been seen in the code below. If I just start up a > connection, place it in a segment and then try to attach to that segment > from another process and use the DBH I get the following error. > > "dbih_getcom handle DBI::db=HASH(0x828e438) is not a DBI handle (has no > magic) at ./connection_pool_client.pl line 59." > > > Any idea why a dbh can not be shared via shared memory? What is trying a > dbh to its original process? What's magic? > > Thanks all. > > > Here is my code > > connection_pool.pl > ============================ > #!/usr/bin/perl > > ########################################################################## > ## > ###### > ## File: connection_pool > ## > ## Des: > ## > ## Author: James Maes > ## > ## Notes: > ## > ## Todo: > ## > ## Bugs: > ## > ## Date: Wed Sep 25 2002 > ## > ## Version: $Revision$ > ## > ########################################################################## > ## > ###### > > use DBI; > use IPC::Shareable (':lock'); > > ########################################### > ## setup the needed global semaphore var ## > ########################################### > %IPC_INIT_OPTIONS = > ( > create => 'yes', > exclusive => 0, > mode => 0777, > destroy => 'yes', > ); > > $STAT_FILES_GLUE = "SFDS"; > > ################################################################ > ## use IPC::Shareable to put shared hashes into shared memory ## > ################################################################ > print "Initializing shared memeory pool\n"; > my $sharedMem; > tie $sharedMem, 'IPC::Shareable', $STAT_FILES_GLUE, { %IPC_INIT_OPTIONS } > or > die("tie write failed."); > > ########################################################################## > ## place the connection in a share memory segment to allow access to it ## > ########################################################################## > print "Initializing database connections\n"; > $dbh = > DBI->connect("dbi:Informix:usermgr\@mldbtcp",,,{AutoCommit=>0,PrintError=> > 1} > ) || print "Error : $!\n"; > $sharedMem->{dbh} = $dbh; > $sharedMem->{name} = "db_connection"; > $sharedMem->{time} = time(); > > > print "Done\n"; > > #################################### > ## make the stdout filehandle hot ## > #################################### > while(1) > { > print " . \n"; > sleep(10); > } > > > > > connection_pool_client.pl > ============================ > #!/usr/bin/perl > > ########################################################################## > ## > ###### > ## File: connection_pool_client.pl > ## > ## Des: > ## > ## Author: James Maes > ## > ## Notes: > ## > ## Todo: > ## > ## Bugs: > ## > ## Date: Wed Sep 25 2002 > ## > ## Version: $Revision$ > ## > ########################################################################## > ## > ###### > > use DBI; > use INFOplus::DB; > use IPC::Shareable (':lock'); > > require "/usr/lib/perl5/5.6.0/dumpvar.pl"; > > ########################################### > ## setup the needed global semaphore var ## > ########################################### > %IPC_READ_OPTIONS = > ( > create => 0, > exclusive => 0, > mode => 0777, > destroy => 0, > ); > > $STAT_FILES_GLUE = "SFDS"; > > > ############################################################ > ## get the stat file hash from the IPC::Shareable segment ## > ############################################################ > my $sharedMem; > tie $sharedMem, 'IPC::Shareable', $STAT_FILES_GLUE, { %IPC_READ_OPTIONS } > or > die("tie read failed."); > > print "Values\n"; > print "dbh = $sharedMem->{dbh}\n"; > print "name = $sharedMem->{name}\n"; > print "time = $sharedMem->{time}\n"; > ## main::dumpValue($sharedMem); > > > $dbh = $sharedMem->{dbh}; > > print "DBH\n"; > ## main::dumpValue($dbh); > $dbh->commit(); > > > print "Connection\n";