Morgoth
06-05-2003, 05:41 AM
Hello,
I have a simple counter running on a page where I want to keep track of how many times the page has been viewed (refreshed).
The code is simple:
Dim FSO, Counter, Error, File, Hits
Set FSO = CreateObject("Scripting.FileSystemObject")
Counter = Server.MapPath("db/counter.txt")
Set File = FSO.OpenTextFile(Counter)
Hits = CLng(File.ReadLine)
Hits = Hits + 1
File.Close
Set File = FSO.CreateTextFile(Counter, True)
File.WriteLine(Hits)
File.Close
Now, as I can see, there is nothing wrong with the code, and I don't recieve errors anytime 'I' view it, but I have noticed, since I have many people viewing this page quite often, and it gets updated alot, is there some sort of FSO bug where when it gets two request at the same time (or something like it) it removes the folder, and starts over with 0?
Is there any explaination?
I have tried to fix this by adding On Error code, and seeing if there is any error with this code, it will end the application right after it checks to see if the file is there. And, I have not seen the text file ever go back to 0, but I can't be sure if my on error code works, or it hasn't be caused yet.
My guess the problem is caused by:
When someone views the page, and it reads what is in counter.txt and it also deletes the file. When it gets deleted, and someone else tries to read the file before it is remade with the new number, it errors, and remakes a new file with nothing inside (Or 1, I can't really be sure. So all the Zeros mentioned above, might be Ones).
Any help on this subject would be... helpful ;)
Thank you.
I have a simple counter running on a page where I want to keep track of how many times the page has been viewed (refreshed).
The code is simple:
Dim FSO, Counter, Error, File, Hits
Set FSO = CreateObject("Scripting.FileSystemObject")
Counter = Server.MapPath("db/counter.txt")
Set File = FSO.OpenTextFile(Counter)
Hits = CLng(File.ReadLine)
Hits = Hits + 1
File.Close
Set File = FSO.CreateTextFile(Counter, True)
File.WriteLine(Hits)
File.Close
Now, as I can see, there is nothing wrong with the code, and I don't recieve errors anytime 'I' view it, but I have noticed, since I have many people viewing this page quite often, and it gets updated alot, is there some sort of FSO bug where when it gets two request at the same time (or something like it) it removes the folder, and starts over with 0?
Is there any explaination?
I have tried to fix this by adding On Error code, and seeing if there is any error with this code, it will end the application right after it checks to see if the file is there. And, I have not seen the text file ever go back to 0, but I can't be sure if my on error code works, or it hasn't be caused yet.
My guess the problem is caused by:
When someone views the page, and it reads what is in counter.txt and it also deletes the file. When it gets deleted, and someone else tries to read the file before it is remade with the new number, it errors, and remakes a new file with nothing inside (Or 1, I can't really be sure. So all the Zeros mentioned above, might be Ones).
Any help on this subject would be... helpful ;)
Thank you.