I'm going to use AJAX/comet to create a chat. And I want to store the chat conversation.
Every keypress will trigger an event that sends to back-end.php that will store the letter. I wonder if I should store it directly in the database or in the textfile.
You don't have to consider the details for exactly how this chat's architecture will be. Just that every letter pressed will be stored immediately.
I thought that if storing in MySQL (I'm using PHP on a comet server) then there will be a lot of queries, just for one letter each. And if a lot of users are chatting, then it will be a heavy load with UPDATE and SELECT queries.
Will storing the conversation in text files be easier for the server? Just open it, append the letter, and close it with PHP.
What do you think?
There will be as many file operations as sql operations. Files may be quicker for some purposes, but databases will scale much better.
I'm surprised you're firing every keypress - do you know how fast some users type??? With Ajax being asynchronous (by default), you will quickly find that your requests are stacking up and this will delay the message being delivered to the chat partner as well as place huge load on your server.
You could downgrade to sending after every word, or even on a return keypress.