how to write concurrent data in json file

PHP enable concurrent and simultaneous writes to json file

Scenario: I have a website hosted which is being accessed by multiple users (1000+), I have to store their selections/choices in a single json file (on server). I use PHP and JQuery for this.

Problem: the code is not able to log data from multiple users. the data is getting overwritten. If I use lock (php) only one user gets to write , and other users data doesnt get saved. I tried append and got horrible results (lots of data repetition)

Looking for: A way to allow simultaneous writes to the json file using php without losing or overwriting data. Or a better approach for storing these user preferences/choices.

I thought of keeping data in localstorage/sessionstorage and commit write on browser exit, but I couldnt find a foolproof way to always catch a browser exit across various avl versions of IE, Chrome, Firefox, safari.




Leave a Reply