Page 1 of 1

incrementing data in txt file - Linux & windows

Posted: Mon May 12, 2003 9:50 pm
by psmshankar
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..

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);
&#125;

Posted: Tue May 13, 2003 2:42 am
by twigletmac
Have you done debugging by echoing each variable in the script to see what their up to?

Mac

Posted: Tue May 13, 2003 2:47 am
by psmshankar
yes.. i chked the count variable and displayed..sometimes its ok..sometimes its incrementing more...
is it becos that that page is accessed by others as well at that time????
thats y i am seeing and increase in the count..???? witihin that short span of time??