推送通知如何工作? [英] How do push notifications work?

查看:28
本文介绍了推送通知如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在基于 PHP 的网站上实施推送通知.目标是制作一些类似于 Stackoverflow 和其他网站在用户收到消息时实时通知用户的内容.

I'm trying to implement push notifications on my PHP-based website. The goal is to make something similiar to what Stackoverflow and other sites have which notify a user in real-time when they get messages.

我使用 mysql 作为我的数据库,Apache 作为我的服务器,并且正在考虑使用 Amazon-SNS 作为这些通知的框架,因为这似乎是该服务的用途.

I'm using mysql as my database, Apache as my server, and am considering using Amazon-SNS as the framework for these notifications since that is what that service seems to be intended for.

我从文献中很难理解如何以编程方式设置 sending.phpreceiving.php 页面.我假设 sending.php 页面只涉及到某个页面的 $_POST['message'] ,但从那里我真的迷路了.

I'm having a hard understanding from the literature how programmatically the sending.php and receiving.php pages are set up. I'd assume the sending.php page just involves a $_POST['message'] to some page, but from there I'm really lost.

如果有什么可以帮助我了解 receiving.php 页面对于推送通知的外观,我将不胜感激.

If something could help me understand what the receiving.php page would look like for a push notification I would greatly appreciate it.

推荐答案

工作

HTML5rocks 在这里提供了关于 websockets 工作原理的很好的解释.

Working

HTML5rocks have provided a good explanation here, about how websockets work.

好吧,您可以将 Websockets 用于支持它的浏览器(因为所有现代浏览器都提供了很好的支持)

Well you can make use of Websockets for the browsers that support it (since all modern browsers provide good support)

您可以从以下几个资源开始:

You can get started with these few resources :

HTML5rocks

Nettuts+

Nettuts+ 提供了一个很好的入门教程 websockets.

Nettuts+ provide a good tutorial for getting started with websockets.

适用于支持 Websockets 的浏览器

您可以使用Modernizr来检测客户端的浏览器是否支持websockets &作为后备,您可以使用 flash 而不是 Websockets.

You can use Modernizr to detect whether the Client's browser has support for websockets or not & as a fallback you can make use of flash instead of Websockets.

对于那些项目,当在没有 WebSockets 或禁用它的浏览器上运行时,web-socket-js 将被使用.它会比原生效率低,但仍然比长轮询低得多.

For those projects, when running on browsers with no WebSockets or with it disabled, web-socket-js will be used. It will be less efficient than native, but still much lower latency than long-polling.

任何带有 Flash 的浏览器都可以使用 web-socket-js shim 支持 WebSocket/polyfill.

Any browser with Flash can support WebSocket using the web-socket-js shim/polyfill.

参考:

WebSockets 的替代方案

https://softwareengineering.stackexchange.com/questions/33713/is-there-an-alternative-to-html-web-sockets-now-that-firefox-4-has-disabled-the

这篇关于推送通知如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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