You can stop others to edit the text while the first user (the one that logged in first) is doing it. To do that, you can add another .json file to save the last activity of users in order of their login times. For example let's say user one logged in at 1585844170 (value of time()
) and 1s later user2. So at this time we have this content in activity.json
{
"user1": 1585844170
"user2": 1585844171
}
By a simple javascript interval (using Ajax) we can update this activity let's say every 1000ms. As a timeout, when we don't get any request for updating this time let's say after 5s we consider that user is gone. So each time that a user sends a request for updating the activity time, he gets a json as a result that says he can start editing yet or not. For example:
{
"updated": true,
"editable": false,
"editingBy": "user1"
}
So when editable is true, we can enable inputs (textareas etc) and let the user to start typing! Also you can show who is editing now!
To understand this better, let's say that user1 is gone (no activity updates for him in last 5s) and now user2 sends an update activity request. In this case user1 will be deleted and user2 is now allowed to edit the text.
{
"user2": 1585844190
}
Note
1. When you receive a request for editing the text in your php file, you should also check whether the user is the one allowed or not (because javascript can be edited by that user)
2. You can make a function for modifying the activity.json file and run it each time you get a request from a user.