I'm trying to control the size of a log file. When it gets more than 5k
oversize, I attempt to trim it thusly:
$fcap = intval(($dval * 0.0108))*1024; // what it should be
$fsize = filesize($file) ; // what it is
$oversize = $fsize - $fcap;
if ( $oversize > 5120 ) // 5k oversize
{
$fp = fopen($file,"r+ ");
fseek($fp, -$fcap, SEEK_END);
$redux = fread($fp, $fsize);
$fp = fopen($file,"w" );
fwrite($fp, $redux);
}
The problem is the file is getting wiped out - reduced to 0k
Doesn't the fseek statement say "move the pointer to the end of the file,
then back up by the amount of $fcap" ? Then, data from the pointer down is
read into $redux, and $redux overwrites $file ?
Am I missing something? Why is my log file getting wiped out?
oversize, I attempt to trim it thusly:
$fcap = intval(($dval * 0.0108))*1024; // what it should be
$fsize = filesize($file) ; // what it is
$oversize = $fsize - $fcap;
if ( $oversize > 5120 ) // 5k oversize
{
$fp = fopen($file,"r+ ");
fseek($fp, -$fcap, SEEK_END);
$redux = fread($fp, $fsize);
$fp = fopen($file,"w" );
fwrite($fp, $redux);
}
The problem is the file is getting wiped out - reduced to 0k
Doesn't the fseek statement say "move the pointer to the end of the file,
then back up by the amount of $fcap" ? Then, data from the pointer down is
read into $redux, and $redux overwrites $file ?
Am I missing something? Why is my log file getting wiped out?
Comment