Re: Rotating Log-Container

From: Date: Wed, 02 Feb 2005 21:07:27 +0000
Subject: Re: Rotating Log-Container
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-35885@lists.php.net to get a copy of this message
On Wednesday 02 February 2005 12:46 pm, Stephan Wentz wrote: > Ian Eure wrote: > | On Wednesday 02 February 2005 12:06 pm, Stephan Wentz wrote: > |>Ian Eure wrote: > |>| On Wednesday 02 February 2005 10:10 am, Stephan Wentz wrote: > |>|>Hmm ok, the part counting the numer of lines doesn't really make sense. > |>|>Has anyone got a good idea how to do this without memory being > > exhausted? > > |>|>:) > |>| > |>| http://packages.debian.org/logrotate > |>| > |>| I really don't think this belongs in PEAR. > |> > |>Please read my first post again and rethink what you wrote ;-) > | > | To answer your question, I think the best thing you can do is run `wc > > -l' on > > | the file. > | > | I think this is still a bad idea, but it's your funeral. > > Hehe, you've got a rather bad attitude toward this ;-) > I have a bad attitude in general. ;^) 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. > "wc -l" was my first thought, but even this isn't accessible on my > managed host :-( > And on Windows-Servers this won't be possible, too. > > Now I have several options, first: leave out maxLines. > Second: use fopen/fgets to get the number of lines. > Third: Get an approximate number by dividing the filesize with an > average number (of characters in a line). > > I tried nr 3, it's of course fast, but unreliable. I then checked nr 2 > and was positive surprise, it only took 0.001 secs for a logfile >10mb. > Setting the size-limit to 1mb should reduce this amount farther. > > So I guess I'll stick with this method until someone has an idea for a > better solution, without using system-calls. > This sort of thing is generally done on a daily basis, though there's no reliable way to do this with your approach. But it's more consistent, since you always know what timeframe a particular logfile represents, instead of having to grep around looking for the right file. PHP doesn't appear to have a function which returns the number of lines in a file, so you're stuck with using an external helper, or loading the file up e.g. with file() and running count() on it.

Attachment: [application/pgp-signature]
« previous php.pear.dev (#35885) next »