Dmitry E. Dmitriev wrote:
> Hi ALL!
>
> Should i still lock my dbm files accessed from cgi under mod_perl if i
> need only read from them? Not my program nor any others never will write
> to
> this files.
Nope, you don't have to. In any case the used lock (flock) is usually
advisory, which means that any other program can still access the dbm
file in the write mode bypassing the lock (it may not know about the
lock's existence.
> I have a problem with code:
>
> use DB_File;
> use strict;
> my %fields;
> my $fieldsdb='/path/to/db_file';
>
> .... some code there ....
>
> if (!(tie(%fields, 'DB_File', $fieldsdb, O_RDONLY, 0666, $DB_HASH)))
> {print "Sorry, database access timeout. $!";}
>
> else {
> ...other code...
>
> if (defined($fields{$key})) {print "Field for $key is
> $fields{$key}\n";}
> else {print "Field for $key not defined!\n";}
>
> untie %fields;
> }
>
> If i run this code from command line or under mod_cgi, it work fine.
> But if it run repeatedly under mod_perl, it occasionally give me a
> "database access timeout" message (see code above), but error value $!
> still empty. I'm confused: why error occurred on tie phase, before any
> read statements?
you don't show all your code, so we cannot tell. Since it doesn't work
under mod_perl, it's probably a problem with your code, which is not
running well in the persistent env. Can you give us a 3-4 lines script
that we can reproduce the problem with? (3 lines should be enough to
test whether a dbm can read/write.
> The second problem is - even after successful tie()-ing of database
> rarely i get "Field not defined!" message for defined keys...
the same thing, please read first:
http://perl.apache.org/guide/porting.html#Sometimes_it_Works_Sometimes_it
and other sections in the same chapter.
Also see:
http://perl.apache.org/guide/dbm.html
p.s. make sure that you enable warnings mode:
http://perl.apache.org/guide/porting.html#Command_Line_Switches_w_T_e
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:[EMAIL PROTECTED] http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/