#1
  1. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,870
    Rep Power
    369

    Multiple users writing into same file? - risk?


    Hi,

    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".
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,233
    Rep Power
    593
    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,870
    Rep Power
    369
    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.

IMN logo majestic logo threadwatch logo seochat tools logo