i have a file on the server where a user can write something to it by using a html form and ajax.
Immediately after he finishes writing and the file is saved, the file gets empty’d.
My problem is if 2 or more users write to the same file.
I need to set some kind of priorities, because i want only one user to write at the time and only after the file gets empty’d then the next user can use it.
Or, if user1 writes to the file and then user2 does the same thing, what happens with the post data from the user2? gets lost or it stays in a q and waits for the file to be ready?
As you can see im a bit confused on how this write and read to file works from this point of view.
All help much appreciated.
thanks
take a look at flock() php function. If you lock file, other scripts will be waiting until you reset the lock.
Another and most times better way. You can use different filenames for different users based on their sessions. It more scalable.