Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Tied hash for CGI-usage (what about file corruption?)

Reply
Thread Tools

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

 
 
Dan
Guest
Posts: n/a
 
      11-21-2003
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??
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      11-21-2003

(Dan) wrote:
> 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

--
I've seen things you people wouldn't believe: attack ships on fire off the
shoulder of Orion; I've watched C-beams glitter in the darkness near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die. |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-|
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tied hash: Differentiating between assignment of single value andentire hash bernd Perl Misc 0 04-24-2012 02:41 PM
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
copying values from a hash into CGI.pm via tied hash reference ioneabu@yahoo.com Perl Misc 14 01-10-2005 01:22 PM
sharing a (tied) hash between processes Thomas Reat Perl Misc 4 01-03-2004 09:42 PM
What is a tied hash? Dan Anderson Perl Misc 5 11-21-2003 10:43 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57