I want to create automatically log files on daily basis for one month and after that old files will be unlinked itself. Following is my code. Am i doing right. If yes then is there any way to reduces filesize on disk.
$KeepDays = 30; # how many days of log files we'll keep on hand
$logname = date("Ymd") . '.status.log';
$OldFile = date('Ymd',mktime(0,0,0,date("m"),(date("d") - ($KeepDays + 1)),date("Y"))) . '.status.log';
if (file_exists($OldFile)) { unlink($OldFile); } # erase oldest log file
if (file_exists('logs/'.$logname)) {
$fp=fopen('logs/'.$logname,'a');
}else{
$fp=fopen('logs/'.$logname,'w');
}
$chunk = "Var1_".$var1.'_'.$Var2.' var3_'.$var3.' var_'.$var.' var_'.$var4 ;
fwrite($fp,$chunk. PHP_EOL);
fclose($fp);
Thanks in Advance.