0

Possible Duplicate:
Implementing Server Push

I want to send a message to the client from php to javascript when some event happens at the server side like for instance the user table is modified or something like this. When the event occurs, the server sends it to the client..How can I implement this ?

If possible without using html5

Community
  • 1
  • 1
Manish Basdeo
  • 6,139
  • 22
  • 68
  • 102

3 Answers3

2

You should have a deeper research on

  • Server Push
  • Ajax long polling / comet

The main "problem" is that your server needs to "know" the users browser, afaik the way to go is to keep a long-time connection open between server & client. Check this: http://jabberwocky.eu/2011/02/02/html5-pubsub-and-browser-push/

Sliq
  • 15,937
  • 27
  • 110
  • 143
2

I know you mentioned you wanted to steer clear of HTML5, but I would advise that the best solution might be one that utilizes HTML5 technologies when available and falls back to a long-polling or frequent-polling solution otherwise. Check out the HTML5 WebSockets API, which was created, at least in part, for this exact purpose. If you are comfortable with Node.js as a backend, Socket.IO is a great framework.

Cecchi
  • 1,525
  • 9
  • 9
1

The only way I can think to achieve this is to leave an AJAX request to the server open for as long as possible and then write to the connection when something happens on the server.

If the AJAX request timesout, you will have to re-initiate it.

There really isn't a way for the Server to connect to the Client in a browser scenario.

Paul Bain
  • 4,364
  • 1
  • 16
  • 30