Tied hash for CGI-usage (what about file corruption?)

D

Dan

Has anyone knwoledge to share about tied hashes as database backend in
cgi-scripts?

I'm running a CGI that will acess a DBM file (DB_File) as a tied hash
like this:

sub pseudo-code{
tie %hash
read(!) something
untied %hash
}

Do I have to use a file lock algorithm wrapped around when I am just
goint to READ from the file?

Will file corruption over time be a problem? (the script will be
running on a heavy load website, multiple processes, maybe sometimes
to read all at once)

As I udnerstand it I'll have to lock the DB_File only for
write/read-write access, but for reading only??
 
B

Ben Morrow

Do I have to use a file lock algorithm wrapped around when I am just
goint to READ from the file?

Will file corruption over time be a problem? (the script will be
running on a heavy load website, multiple processes, maybe sometimes
to read all at once)

As I udnerstand it I'll have to lock the DB_File only for
write/read-write access, but for reading only??

[this applies much more generally than tied hashes]

If anyone is going to be writing, then *everyone* has to lock. Readers
lock with LOCK_SH, writers with LOCK_EX. See the documentation for
DB_File for some important caveats when locking. If you have control
of every program accessing this database, it is probably a better idea
to use a lockfile: lock the file before you tie, and untie before you
unlock.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top