> -----Original Message-----
> From: Andy McDowell [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, November 15, 2001 6:37 AM
> To: [EMAIL PROTECTED]
> Subject: Some advice needed on file locking with modperl'ed code
> 
> 
> Hi All,
> 
> I am writing a modperl webapp (the new web interface for the 
> RipeNCC whois
> database server) and I have need to store some data to a file.
> Nothing heavy, just a few one liners like user query strings, 
> screen used,
> server process time and a few others to do some analysis work 
> on potential
> bottlenecks and whois query trends.
> 
> The page will take about 5 hits a second when put into 
> production. Since its
> modperl, this means multiple instances of page will be 
> running concurrently on
> the webserver.
> 
> Now the question:
> 
> Will I need to use File::Flock to avoid write problems by 
> simultaneous writes to
> the one file by concurrent instantiantions of application?

Yes, I would recommend using locking. If the processes are appending
to a log file, you can get away without locking if you use unbuffered
writes (i.e. syswrite()) and make only a single call to write your
log data. The kernel will keep these from getting intermixed.

If you do use locking, you need to be sure the lock gets released
at the end of the request, which can be an issue since the Apache/mod_perl
process is long-lived. The easiest way IMO is to localize the file
handle, so Perl will automatically clean it up no matter how your
scirpt ends. If using Apache::Registry, you can also put your close/
unlock in an END {} block (see mod_perl manpage).

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to