6

I'm using Zend Framework for an application called Pricetag, and we're thinking of adding support for real-time multi-user editing. Basically the idea is, in each of 4 steps, to be able to share what you're editing with other online users (much like Pivotal Tracker or Trello does).

This is a screenshot of the most complicated (programmatically speaking) of the four pages we have:

Pricetag Step 2 screenshot

Internal HTML is not important (but hey, you can register as a free user if you want to check it out), basically some inputs and the ability to add/delete these blocks ("deliverables" and "tasks") with javascript.

I assume I need some way for the server to notify each online client about changes in the page. I'm already doing a request every time you change something (the white block on the right updates every time you do so), but I don't know exactly how other users would receive that information.

Polling the server every 5 seconds or so seems very very wrong. The site uses PHP, is that enough to do it? Should I interface with a separate script in the server? Is there a Zend Framework module already built that I'm missing even though I asked Google first?

Andrei Petrenko
  • 3,922
  • 3
  • 31
  • 53
cambraca
  • 27,014
  • 16
  • 68
  • 99
  • Something like [Pusher](http://pusher.com/) comes to mind for the event notification if you don't want to use polling. In this case the event notification to each user would be nearly instant with no polling required. – drew010 Nov 16 '11 at 01:56
  • Interesting.. I'm wondering what strategies the "big boys" use. I didn't know about Pusher, but I'd like an answer from someone that tried many options and succeeded with one.. – cambraca Nov 18 '11 at 02:51

4 Answers4

6

Try this comet server - http://dklab.ru/lib/dklab_realplexor/

It's has PHP and javascript API, see the sandbox for examples - http://rutwit.ru/realplexor/demo

Comet server written in perl, the source and tarball files are available here - http://github.com/DmitryKoterov/dklab_realplexor/tarball/master

see other technologies -

Tornado Web Server. Web server writed on Python, it's not onlye comet server - it's a framework where you can create a comet server.

NginxHttpPushModule: simple module for nginx web server, that adds support for Comet.

CometD: scalable HTTP-based event routing bus that uses a Ajax Push. Supported subscribe on many channels.

APE: It's rather a framework for building the comet-systems than finished product.

Stardust - simple COMET server in perl (comment of author — "the simplest COMET server I could imagine").

Orbited: emulation of TCP sockets in JavaScript.

Andrei Petrenko
  • 3,922
  • 3
  • 31
  • 53
2

Take a look at socket.io library. It uses a bunch of techniques to notify clients asynchronously.

Andrei Petrenko
  • 3,922
  • 3
  • 31
  • 53
1

We experimented with using Comet for a chat client of sorts a while ago. The basic premise is you open a connection (likely an AJAX request) to a web server and hold it open until either

  • The timeout expires (say 30 seconds),
  • or some application state occurs that requires data to be sent to the client.

At that point, the request returns. If there is a payload, apply whatever needs to be done, then make the request again which starts the process over.

The only major drawback we encountered was with many connections being held open (just sitting there waiting for a response) we quickly exhausted the thread count in Apache and future ones were stalled. At that point we abandoned the exercise (for other reasons however) so never looked into possible fixes.

The other challenge was getting separate PHP threads to talk to one another, which was equally not an easy feat. As I recall we ended up using something built on sockets and each thread could talk to another given a unique ID (I didn't work on this bit myself, so I'm not sure if this is entirely correct). In your case you may be able to check for mod time on a DB or file then return when a modification occurs.

I would imagine that things would have progressed since we tried this (it was a few years ago), but I suspect the general idea still remains and libraries have leveraged that.

phindmarsh
  • 879
  • 6
  • 11
0

Many of the "push" libraries actually revert to polling the server every few seconds.

We implemented a chat script to keep open the connection but it ended up in problems with some customers and their firewalls. I wouldn't do that again. If you keep the connection open don't use HTTP on port 80.

It's also a matter of that the PHP script does. Doing a database query every few seconds to every client might be slow. We circumvented this with writing a static HTML file which the ajax polled every few seconds for changes. Most of the times server reported Not Changed (301?). THis is a tiny load to server and often further minisculed by HTTP Keep-alive. If you still think you can't load your server you can also rent webspace to host the static file(s).

Antti Rytsölä
  • 1,485
  • 14
  • 24