A friend of mine and I have been using Google Docs for a while but it seems to be in the process of not supporting her browser anymore so as a fun project I thought I would try to imitate its functionality myself.
So far I’ve built a working facsimile in Codeigniter (PHP) that works fine on my machine locally; however, I’m trying to figure out if it is the most effective approach/safest to unleash on other people. (Bear in mind that this is not meant to be a public service; just for use by mostly 2 people, maybe 3-4 at most.)
Each page of the app has a chat room and a view for whatever the current document is; these are refreshed independently. The chat room basically pulls from a .txt file which is updated every time the user submits a message; the chat refereshes via a JQuery AJAX call twice per second. (So far I’m not bothering with trying to note when a user left the chat, though I assume that would take a separate poll.)
The document view also updates via AJAX, but calling a controller function to ping a document MySQL database instead; this call happens once per second as well as any time a user updates the document.
Clearly this is going to have to be on a hosting plan that can accomodate traffic from the regular Javascript calls, but that aside, is this an acceptable way to approach the problem? Will it cause undue strain on the client side (or on the server)? Is there a better way? I’m very very self-taught, and while I’m able to make something that works, I would love to have some confirmation that I’m not taking the wrong approach.
Thanks! Hopefully this question makes sense; glad to elaborate if necessary.
I think polling would cause scaling problems, though that might not be an issue for such a small environment.
I’m not an expert at this either, but I suspect that the model you’d want to use if possible is to leave a socket open with your server so that events (i.e. other people’s edits, or even just the signal to refresh content from the database) could be pushed from the server rather than require polling. There’s a technique called Comet for this. Of course, you’d need to build support for BOTH, in case something like a forced proxy or restrictive firewall gets in the way of the open socket and you need to revert to polling.
On the server side, optimize optimize optimize. If you’re polling, make sure you test a timestamp for the last update that’s kept in a separate, smaller, properly indexed table from your data.
For the chat, why not leverage some of the existing tools out there? There are excellent IRC clients like IRIS. Using an IRC server might also provide a better way for multiple users to coordinate their actions. For example, there could be a channel named for a document identifier that gets joined by a JS handler that notifies others of cursor position, pending edits (and the resultant need to refresh the document from the database), etc. I’m not suggesting that this is the best way, but it’s at least an interesting idea.
I’d love to see the code you come up with! A usable multi-user Google Docs clone would be VERY popular.