Hi, monks. We have a very trouble. We want to use BerkeleyDB for store data (analog Shared Memory).
We write a interface for this - MyMemory.pm module.
package MyMemory; use strict; use Data::Dumper; use MIME::Base64; use BerkeleyDB; use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION); require Exporter; $VERSION=0.1; @ISA=qw(Exporter); @EXPORT=qw(get_memory set_memory clear_all_memory SerializeR UnSeriali +zeR); my $filename = "/home/test/mem.db"; my %h; tie %h, "BerkeleyDB::Hash", -Filename => $filename, -Flags => DB_CREATE or die "Cannot open file $filename: $! $BerkeleyDB::Error\n"; sub get_memory { my $Key=shift; return UnSerializeR($h{$Key}); } sub set_memory { my $Key=shift; my %Value = @_; $h{$Key}=SerializeR(\%Value); } sub clear_all_memory { %h={}; } sub SerializeR { my $SValue = shift; my $SSerialized; if (ref $SValue eq "HASH") { $SSerialized = "HASH"; while (my ($key, $val) = each %$SValue ) { $SSerialized .= enc +ode_base64($key) . ':' . SerializeR($val) . ';'; } } elsif (ref $SValue eq "ARRAY") { $SSerialized = "ARRAY"; foreach my $var (@$SValue) { $SSerialized .= SerializeR($var) +. ';'; } } else { $SSerialized = $SValue; } return encode_base64($SSerialized); } sub UnSerializeR { my $SSerialized = decode_base64(shift); my $SData; if ($SSerialized =~m/^HASH/) { my %HData; my @ATMP = split /;/, substr($SSerialized, 4); foreach (@ATMP) { split /:/; $HData{decode_base64($_[0])} = UnSerializeR($_[1]); } $SData = \%HData; } elsif ($SSerialized =~m/^ARRAY/) { my @AData; my @ATMP = split /;/, substr($SSerialized, 5); foreach my $var (@ATMP) { push(@AData, UnSerializeR($var)); } $SData = \@AData; } else { $SData = $SSerialized; } return $SData; } 1;

In browser:
Software error:
BerkeleyDB Aborting: Database is already closed at /usr/local/lib/perl5/site_perl/5.8.6/mach/BerkeleyDB.pm line 1204.

We have a 25-30 httpd procesed (mod_perl). And I think, when we use get_memory from first process - we don't have any error, but when we use get_memory from second process - we have a error;

If we write "tie %h ..." in get_memory and set_memory subs - we don't have error, but we have a too many connections to BerkeleyDB.

Please help...

P.S."Sorry for bad English. I work on this."

In reply to mod_perl & BerkeleyDB. Need help. by STork2000

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.