Re: Rotating Log-Container

From: Date: Wed, 02 Feb 2005 21:19:05 +0000
Subject: Re: Rotating Log-Container
References: 1 2 3 4  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-35886@lists.php.net to get a copy of this message
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ian Eure wrote: | 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. Yea you're right with this one, but an external tool would have the same problems. Logfiles on our server grew large in a speed you can't imagine, and I don't wanna switch logs off, so I have to do *something* |>"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. Guess I'll only stick with filesize and mtime, and leave number of lines out. Costs are too much for this one. This should minimize io, and I'll have to live with the problem of a race condition, but this wouldn't be different with an external tool. Thanks for your (negative? hehe) insights ;-) Stephan -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCAUPJ8qQ9XV7tBNQRAo2pAJ0VluzpozL1FYnuvH+J1tgaIGC0fwCdGhSB c0R70YM/ICzzy6RjNogXwIk= =Nf5T -----END PGP SIGNATURE-----

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