I wrote a very simple AJAX chat app with jQuery. It simply sends your message to a PHP file via AJAX, then writes that message JSON-encoded into a text file for the receiver to pick up. The JSON file is simple, like {“userid”:1,”msg”:”hello there”}, and its stored under the receiver’s user ID. Once the receiver detects a timestamp change on the file, it reads the JSON data out of it.
This works well, and it’s very fast. But now I’m considering scaling etc, and I am unsure how filesystem-based chat like this would work long-term. Should I seriously consider an XMPP server and rewrite the Ajax stuff around it, or keep what I have? Thanks in advance.
If scalability is your concern, then I would definitely consider replacing AJAX with XMPP even if your app has no chat capability in it at all. Although XMPP has a lot of complexity in it at the protocol level, Strophe does a great job at abstracting away that complexity. Here is some sample code that does the XMPP equivalent to an AJAX call.