简体   繁体   中英

Push notifications from server to user with PHP/JavaScript

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.

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

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

ScaleDrone允许您使用PHP API 客户端从 PHP 推送到 JavaScript。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM