在客户端阵列上持久存储服务器端数据 [英] Persisting server-side data across an array of clients

查看:183
本文介绍了在客户端阵列上持久存储服务器端数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP网站和一个SQL数据库。用户将能够使用手机更新此数据。我希望所有用户都能收到这些更新。我将如何做到这一点?

I have a PHP website and a SQL database. Users will be able to update this data with a mobile phone. I would like all users to receive these updates. How would I do this?

我可以简单地使用ajax和一个计时器让每个客户端请求更新在给定的时间间隔。

I could simply use ajax and a timer to have each client request updates at a given interval.

有没有办法设置回调的排序,使服务器上的服务调用方法实例列表?这将避免不必要的请求和数据传输...

Is there a way to set a callback of sorts so that a service on the server calls a list of method instances? This would prevent unnecessary requests and transfer of data...

推荐答案

如果您不想使用第三方解决方案像一个@Alexandre Martin建议的,你可以使用服务器发送事件。流程如下:

If you don't want to use a third-party solution like the one @Alexandre Martin suggested, you could use Server Sent Events. The flow is as follows:


  1. 每个用户订阅一个频道(认为它是在连接上注册一个事件侦听器)。在服务器端,脚本连续运行以跟踪更改

  2. 用户向服务器发布更新。

  3. 脚本通知更新并发出活动

  4. 订阅频道的所有客户都会收到活动,阅读其资料属性并更新其本地模式。 / li>
  1. Each user subscribes to a channel (think of it as registering an event listener on a connection). On the server side, a script is running continuously to track for changes
  2. A user posts an update to the server.
  3. The script notices the update and issues an event
  4. All clients who subscribed to the channel receive the event, read its data property and update their local models.

请参阅这个简介,带有示例PHP实现。

See this introduction, with sample PHP implementation.

您还可以使用Web套接字。以下是两者的比较。在实施之前,请考虑浏览器兼容性

You could also use Web Sockets. Here is a comparison of the two. Before implementing either, consider browser compatibility.

这篇关于在客户端阵列上持久存储服务器端数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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