39

Short: Is there a way to push data from the server to a logged in user session without that user needing to make an HTTP request?

Long(er): I'm building an HTML5 application, on an Apache/PHP/MySQL server, that could be served to users on mobile devices (or perhaps via a PhoneGap application).

I would like to let the user know when there is new information available from the application, without racking up excessive data charges by forcing that user to execute a call to the server, or requiring AJAX calls (yes I know it could check for a single byte cookie, but I'd rather make it zero).

A good example of this would be sending chat messages between two users on submit from one user to the other.

3
  • I'm doing my research into WebSocket's thanks to the feedback I've recieved. I found an awesome tutorial over at: net.tutsplus.com/tutorials/javascript-ajax/… Commented Feb 2, 2012 at 3:56
  • 1
    Why was this closed? It's a real question ... Commented Apr 9, 2013 at 13:54
  • 1
    It is a real question, but one that is broad and not clear. An 'obvious' answer would be, "ofcourse", as sure, there are ways to push data from a server without using HTTP, for instance using ANY other protocol. The problem seems to be 'excessive data charges', but how would another protocol fix that? It looks like 'sockets' is the answer, but that's not a real obvious thing to suggest based on the contents of the question in my opinion.. Maybe if the question is clarified a bit? Commented Mar 10, 2014 at 14:30

3 Answers 3

29

In modern browsers, Websockets or in older browsers, "long polling". There are also libraries that can abstract some of this (like comet).

A very common library in use now is socket.io which automatically connects with the best technology available, using webSockets if available and falling back to other technologies like long polling if not available.

Some other references:

How do I implement basic "Long Polling"?

COMET (server push to client) on iPhone

More on Long Polling

Is there a difference between long-polling and using Comet

Pushing the web with websockets

Oh HTML5, Push Data to my Mobile

Sign up to request clarification or add additional context in comments.

2 Comments

Superbly helpful. I'll start doing my homework on Websockets ASAP.
Added socket.io reference which is now very useful.
4

I recommend Socket.io

It leverages

WebSocket, FlashSocket, HTML file(for IE), XHR long-polling, JSONP-polling

It is with Node.js which means it is on non-blocking nature.

In realtime feature, concurrency is a big issue

so the non-blocking nature of Node.js and Socket.io would help you

1 Comment

I'm wary of Node.js, but this is very helpful. Thanks!
1

ScaleDrone lets you push from PHP to JavaScript using a PHP API client.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.