incrementing data in txt file - Linux & windows
Posted: Mon May 12, 2003 9:50 pm
Dear All,
my code to increment the page visit count works fine in windows.i did the same in linux, given the appopriate rights to counter.txt file where i am writing the count value... it actually counts but sometimes it counts high..like it increments by 3 or 2.... i donno why
in windows its perfect..wheever i refresh the page count increases by 1, whereas in linux box, sometimes it goes off to high value say from 97 to 104 somethinh like that..
my code to increment the page visit count works fine in windows.i did the same in linux, given the appopriate rights to counter.txt file where i am writing the count value... it actually counts but sometimes it counts high..like it increments by 3 or 2.... i donno why
in windows its perfect..wheever i refresh the page count increases by 1, whereas in linux box, sometimes it goes off to high value say from 97 to 104 somethinh like that..
Code: Select all
if (file_exists($COUNT_FILE))
{
// Open, read, increment, save and close file.
$fp = fopen("$COUNT_FILE", "r+");
flock($fp, 1);
$count = fgets($fp, 4096);
//echo "<br> count = $count";
$count += 1;
//echo "<br> count = $count";
fseek($fp,0);
fputs($fp, $count);
flock($fp, 3);
fclose($fp);
}