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

Discussion in 'Perl Misc' started by Dan, Nov 21, 2003.

  1. Dan

    Dan Guest

    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??
     
    Dan, Nov 21, 2003
    #1
    1. Advertising

  2. Dan

    Ben Morrow Guest

    (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. |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-|
     
    Ben Morrow, Nov 21, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rp
    Replies:
    1
    Views:
    596
    red floyd
    Nov 10, 2011
  2. Dan Anderson

    What is a tied hash?

    Dan Anderson, Nov 21, 2003, in forum: Perl Misc
    Replies:
    5
    Views:
    320
    Tad McClellan
    Nov 21, 2003
  3. Thomas Reat

    sharing a (tied) hash between processes

    Thomas Reat, Jan 1, 2004, in forum: Perl Misc
    Replies:
    4
    Views:
    139
    pkent
    Jan 3, 2004
  4. Replies:
    14
    Views:
    273
    Tomi Häsä
    Jan 10, 2005
  5. bernd
    Replies:
    0
    Views:
    650
    bernd
    Apr 24, 2012
Loading...

Share This Page