For logging (without searching), appending to a flat file is fine. The overhead of a database isn't worth it, and it's easy enough to parse the textfile into a database later, if you need.
As for the actual chat-room part, I would start with a simple database table, an <input>
and a div to display the messages.
Get that working (no fancy updating), then use Javascript (or one of the Javascript frameworks, I'd recommend jQuery) to clear the chat <div>
, grab the last 10 messages and display them in the chat div (every 20 seconds, say)
Then try and append new chat messages to the div, rather than clearing it.. One way would be, grab the last 10 messages as JSON every 20 seconds, including a unique message id (autoincrement would be fine). Keep an array of received message id's. On each refresh, check if the current messages id is in the array, if not, append it.
The HTML should be pretty simple, something like
<div id="chatmsgs">
</div>
Then you append within that div..
<div class="msg">
[message content]
</div>
Using the jQuery functions getJSON and append should be all you need..
Then look into "long polling", basically you have a page that waits until new data before sending any content. You request this like a regular AJAX'y XmlHttpRequest, but rather than requesting the URL every x seconds, getting a blank page, you request the page once, and the page load only completes when a new message arrives. When you get data (or the connection times out), you deal with it, and wait again.. My answer (err, and question) "Simple "Long Polling" example code?" might explain it better.. The problem with long-polling is it quickly ties up all worker-thread based
Or, you could cheat and use Juggernaut (a perfectly reasonable solution)