Below I'm asking what are common ways to do a few things with log files
written by a Registry script.

In summary:
- does opening a file once per child save much time over once per request?
- is writing to a log file without locking crazy?
- what's a good way to gzip and purge live log files?

(Yes, I've read the guide about locking.  Here's I'm keeping the file
handle in scope on purpose.)


I'm wondering if opening a file once per child (instead of per request)
saves me much time and/or might cause me much of a headache.

In a Registry script I open a file the first request and set a global
variable flag.  Then for each request I just flock( FH, LOCK_SH ) and
flock( FH, LOCK_UN).

The only problem I see is that if the lock isn't released I need to do a
graceful restart to get rid of that lock.  (But that would require a bug in
my program and I haven't put any in, yet.)

If I open a file once and do many many LOCK_SH without LOCK_UN I don't
think I'll be leaking, as it's on the same file handle.  Is this a correct
assumption?

Now, the file that is being written to is a log file (not the Apache log
file).  I don't LOCK_EX when writing to the log file.  I have not found any
problems with this method, as I'm writing one full line in a single print,
and it seems as if the (unix?) buffering tends to not mix output with a
small output line (of say 100 characters).

Has anyone else used this method and ended up with mixed output for single
prints and small amount of text?  Or does this seem safe enough?

I do a LOCK_SH because I have a cron job that does a LOCK_EX for processing
-- such as purging or moving the log file.  I don't want any requests
writing at that point.

A reason I don't do a LOCK_EX in the Registry script is that if I leak a
LOCK_EX lock then everything shuts down.  Plus those requests are served so
much faster if I don't waste time locking ;)

Can anyone recommend a good method to archive a log file such as this on a
live system?  I was just going to open for read/write, LOCK_EX, gzip it or
some such thing, then truncate the live log file then close releasing the
LOCK_EX.  It t would probably be faster to first copy/truncate/unlock and
then to gzip, so I don't keep the LOCK_EX too long.

Anyway, just looking for ideas.

Thanks,

Bill Moseley
mailto:[EMAIL PROTECTED]

Reply via email to