> A good structure would be to have one file for each possible answer and
each
> file contains the number of votes it has recieved.
> Then:
> --> Open file for the chosen option as read only
> --> Read the value in the file
> --> Close the file
> --> Increase the value by one using ++
> --> Open the file again in write mode
> --> Lock the file
> --> Write the new value to the file - old one overwritten
> --> Unlock the file
> --> Close the file


That's a bad method. You have to have the lock around the read and the
write. With your method, 5 users might read the file, all getting 99 for the
count, and then each one will try to seperatly write 100 to the file. So you
lose 4 actual counts. You want to open the file, read it, update value,
write it, unlock, and close the file.

Using multiple files would just be a waste of space in my opinion. A locked
file doesn't stop the script, it simply waits for the file to be unlocked
and then continues on.

---John Holmes...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to