Re: Rotating Log-Container

From: Date: Thu, 03 Feb 2005 14:06:06 +0000
Subject: Re: Rotating Log-Container
References: 1 2 3 4 5  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-35918@lists.php.net to get a copy of this message
Hi Stephan, Ian & al.
| But seriously, this is not a safe thing to be doing. It's terribly race-prone, | since you have no idea how many readers/writers the file has at any given | moment, and you stand a very good chance of corrupting things. Yea you're right with this one, but an external tool would have the same problems.
Actually as you rotate (delete or rename) the current log file, you have a chance some other process has this file allready opened and wants to continue to write some log. If you rename the file, this other process will finish to write in this renamed file. If you delete the file, this other process has a *good chance* to loose its next lines in log, what is certainly bad. (tested with CLI concurrent scripts under linux) So, at least, you should never delete the current log file ($maxfiles >= 2 is a rule). The question of evaluating the size of the log should just use filesize. No need to complicate trying to get it in real time. As said you have perhaps concurrent scripts so they also push the size in mean time. If I assume, no very long processes will write big amounts of log in on run, a simple filesize before open is enough and doesn't cost. Anyway, why are you fixing on number of lines ? Just size is critical ? Hope that make sense. -- bertrand Gugger (toggg)

« previous php.pear.dev (#35918) next »