Jump to content

Archived

This topic is now archived and is closed to further replies.

prattmic

Auto-Prune Log

Recommended Posts

[code]<?php

$file = "./logs.txt";
$limit = "5";

$log = file($file);
$lines = count($log);

if ($lines > $limit + 19){

if (!$handle = fopen($file, 'w')) {
echo "Cannot open file ($file)";
exit;
}

for ($i = 0; $i <= 18; $i++) {
fwrite($handle, $log[$i]);
unset($log[$i]);
}

$i = 0;
while (count($log) > $limit) {
unset($log[$i]);
$i++;
}

foreach ($log as $line) {
fwrite($handle, $line);
}

fclose($handle);
 
}
 
?>[/code]

Don't beg for code in the future please.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.