使用PHP / JavaScript将通知从服务器推送到用户 [英] Push notifications from server to user with PHP/JavaScript

查看:131
本文介绍了使用PHP / JavaScript将通知从服务器推送到用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短:有没有方法将数据从服务器推送到登录用户会话,而无需该用户发出HTTP请求?

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?

长(er):我正在Apache / PHP / MySQL服务器上构建HTML5应用程序,可以在移动设备上(或者通过PhoneGap应用程序)向用户提供。

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).

我想让用户知道应用程序何时有新信息,而不是通过强制该用户执行对服务器的调用来消除过多的数据费用,或者需要AJAX调用(是的,我知道它可以检查单个字节的cookie,但我宁愿使其为零)。

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).

一个很好的例子是

推荐答案

在现代浏览器中, Websockets 或在旧版浏览器中,长轮询。还有一些图书馆可以提取其中一些(如彗星)。

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

现在使用的一个非常常用的库是 socket.io

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.

其他一些参考:

如何实施基本的长轮询 / a>

How to implement basic "Long Polling"?

COM上的COMET(服务器推送到客户端)

更多关于长时间投票

长轮询和使用Comet之间有区别

使用websockets推送网络

Oh HTML5,将数据推送到我的移动设备

这篇关于使用PHP / JavaScript将通知从服务器推送到用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆