Dear Monks,
I am running my web tool in 2 instances in AWS using the load balancer. But it's definitely not an AWS issue. Probably I am doing it in a wrong way. This is user records coded like this:
sub user_record { my $count = hit_counter($user_count_file); open (IF, ">>$user_records_file") or die "Cannot open $user_records_fi +le\n"; my $str = "----------------------------------------------------------- +\n"; $str .= "count: $count\n"; $str .= mytime()."\n"; $str .= "ip adderss: $ip_ad\n"; $str .= "User Agent: $http_user_agent\n"; $str .= "Query: $query\n"; $str .= "Search Type: $search_type\n"; print IF $str; close IF; return; } #================= sub hit_counter { my ($countfile) = @_; open(CNF,"<$countfile"); my $count = <CNF>; close(CNF); chop($count); $count++; open(CNF,">$countfile"); print CNF "$count\n"; close(CNF); return $count; }
I am getting some results in a wrong order:
----------------------------------------------------- count: 266 2011:6:1:13:49:31 ip adderss: 24.60.87.27 User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; Query: Search Type: ----------------------------------------------------- count: 270 2011:6:1:13:50:2 ip adderss: 24.60.87.27 User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; Query: Search Type: ----------------------------------------------------- count: 269 2011:6:1:13:49:55 ip adderss: 24.60.87.27 User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; Query: Search Type: -----------------------------------------------------
There is definitely an issue with appending to the same file. Any idea how to fix it?

In reply to Writing to the same file from different instances by vit

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.