I have followed this approach that is described here to implement a simple chat application: https://code.tutsplus.com/tutorials/how-to-create-a-simple-web-based-chat-application--net-5931
I'm writing to a file and reading from the file.
I want to implement a feature that saves the chat history when the chat is not active (when no one has written something in a while).
To do that, I would take the file with the chat messages, read It and insert every message as rows in the database. After the insert to the database is finished, I will remove the file.
Next time someone visit the chat, the history is fetched from the database.
When someone starts to write new messages to the chat, I would go with the same approach: Write to a new file, then read from the file.
But I was wondering about the performance here.
As you can see, a ajax-request is made every 2,5sec to the backend that reads the file and return it's content.
My question is: Is this a valid way to go and is it more efficent to read from the database instead of a file on the filesystem every 2,5sec?