September 9th, 2013, 05:46 AM
Multiple users writing into same file? - risk?
I know there may/will be issues with multiple users accessing the same file concurrently. My question is will this corrupt the file in any way?
I have created this system whereby all user data is going through to one file. I then realised this may cause some issues so I decided to "test" it. What I did was to let this process carry on but also write user data to individual files (i.e. one file per user). I just "counted" all these individual files and they match up to the no of rows in my "all" file.
So I just wanted to ask if this is risky (ie one file for all users) and did I just get lucky? Just to let you know in one day there were 900 users writing to the file so the chances of them typing at the same time are pretty high. In fact I have checked the modified time of those individual files and there are indeed some files that have the same time yet they have managed to go on to the "all file".
September 9th, 2013, 07:08 AM
The quick answer is yes (plus there is a lost records problem to consider). It sounds like you need to be using a database instead. However, if you insist on using a single file for multiple users, you need to set up some kind of locking mechanism which in and of itself is non-trivial. That is why most people use a database.
Last edited by gw1500se; September 9th, 2013 at 07:19 AM.
There are 10 kinds of people in the world. Those that understand binary and those that don't.
September 9th, 2013, 08:18 AM
the reason i didnt do that is because it was the end of the day and they were going to send emails to the users and we didnt want to lose the data so as a quick fix i just dumped all $_POST data to a file. then during the weekend i realised that it may have problems so i added it so that each data created a new file instead of using the same.