Hello, monks! I have built much of my living around the help wanted ads on my web site. Hence it is important that an incoming help wanted ad actually get recorded into the flat-file database I'm using.

Most of the time life is good. Alas, sometimes the database seems to be too busy to allow the incoming data to be written, meaning the web server times out after the employer/customer has clicked the "submit" button.

Clicking the submit button basically runs this code in a Perl script:

open my $dbh, ">>", $database_file_w_path or die "Trouble opening $database_file_w_path, stopped: $!"; flock $dbh, LOCK_EX or die "Can't get LOCK_EX flock for $database_file_w_path, stopped +: $!"; print {$dbh} "$database_row\n"; close $dbh or die "Trouble closing $database_file_w_path, stopped: $!";

I'm wondering if anybody can suggest improvements. When the flock fails and the script dies, currently the customer just sees a blank screen. I can modify the script to spit out some HTML to notify the customer that the site is too busy, but that's not too much improvement in terms of getting money on the table. Does anybody use a loop after such a flock fails initially, to try a second or third time and notify the customer that the order is still being processed?

Perhaps the only answer is to go to a relational DB?

I have tried to get the database "out of the way" on the read side, by having the other script (which reads and displays the content of particular ads) open the database, slurp all the lines into @lines, and then close the database "right away," rather than having a big loop in the fashion of "while my $line=<$file_handle> {"

Ya think that makes a difference in preventing flock failures on the write-side?

Many thanks!


In reply to Append to a busy flat-file db without leaving customer in lurch by davebaker

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.