简体   繁体   English

共享主机上的实时通知(PHP,MySQL,Yii)

[英]Real time notifications on shared hosting (PHP, MySQL, Yii)

I'm currently developing a website that requires a push notification style system like Facebook notifications. 我目前正在开发一个需要推送通知样式系统(如Facebook通知)的网站。 I would like the user to be notified when an event occurs such as "X added you as a friend"... 我希望在发生诸如“ X将您添加为朋友”之类的事件时通知用户...

I've been looking into my options however they seem to be extremely limited as the website will be hosted on a shared hosting platform therefore I have limited access etc. 我一直在研究我的选择,但是它们似乎非常受限制,因为该网站将在共享的托管平台上托管,因此我的访问权限受到限制等。

1) Looking at long polling comet style - as I can't run Python on the server, my only option here is PHP for the server script however due to thread consumption this probably isn't a very scalable option. 1)查看长轮询彗星样式-由于我无法在服务器上运行Python,因此我唯一的选择是服务器脚本的PHP,但是由于线程消耗,这可能不是一个非常可扩展的选择。

2) WebSockets - these look great but with browser support limited it doesn't seem plausible just yet.. 2)WebSockets-看起来不错,但受浏览器支持的限制似乎还不合理。

So - has anyone accomplished this on a shared hosting platform? 所以-有人在共享托管平台上完成此操作吗? I'd rather not have to use a service like Pusher. 我宁可不必使用Pusher之类的服务。

Many thanks!! 非常感谢!! :) :)

PS - I'm using Yii framework - any solutions with that in mind would be even better PS-我正在使用Yii框架-考虑到这一点的任何解决方案都将更好

use Ratchet , it is a WebSocket for PHP. 使用Ratchet ,这是一个用于PHP的WebSocket。

Ratchet is a loosely coupled PHP library providing developers with tools to create real time, bi-directional applications between clients and servers over WebSockets. Ratchet是一个松散耦合的PHP库,为开发人员提供了一些工具,可以通过WebSocket在客户端和服务器之间创建实时双向应用程序。 This is not your Grandfather's Internet. 这不是您祖父的互联网。

here is a helloworld example. 这是一个helloworld示例。

Use html5 SSE (Server sent dom events) for chrome, firefox, opera and ie10 对chrome,firefox,opera和ie10使用html5 SSE(服务器发送的dom事件)

for older versions of IE use iframe loading as a fallback. 对于较旧版本的IE,请使用iframe加载作为后备广告。

all those techniques should work well with any kind of shared hosting since they do not require any kind of server side setup. 所有这些技术都可以与任何类型的共享主机一起使用,因为它们不需要任何类型的服务器端设置。

https://stackoverflow.com/a/1086448/1063333 : https://stackoverflow.com/a/1086448/1063333

A common method of doing such notifications is to poll a script on the server (using ajax) on a given interval (perhaps every few seconds), to check if something has happened 进行此类通知的常用方法是,以给定的时间间隔(也许每隔几秒钟)轮询服务器上的脚本(使用Ajax),以检查是否发生了某些情况

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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