Ajax的推送系统 [英] Ajax push system

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

问题描述

在我自己的系统,我有一个 PHP 网​​页,其中显示了所有我已经通过我的在线网店销售的货物,从最新交易到第一位。

In my own system, I have a PHP page which displays all the goods I have sold through my online webshops, from the latest transaction to the first.

我想这将自动更新,每当人们买东西了我。

I would like this page to automatically update, whenever people buy something from me.

我可以让 AJAX 每次调用的 5 的秒来检查我的数据库中的订单,但似乎1980年? 或者是这样的人做呢?

I could make AJAX call every 5 seconds to check the orders in my databases, but that seems 1980? or is it that way people do it?

我怎么能去的的通知我的 PHP 页,每当我的PHP的 newOrder()的功能(让称呼它)被称为?

How can I go about pushing a notification to my php page whenever my php newOrder() function (lets call it that) is called?

推荐答案

可以实现推送PHP内,但它不会是最有效的解决方案,因为实现推你需要保持你的客户端和服务器之间的长期运行的连接(HTTP或WebSocket的连接)。

You can achieve push within PHP but it won't be the most efficient solution because to achieve push you need to maintain long running connections between your client and your server (HTTP or WebSocket connections).

请参阅:

  • <一个href="http://stackoverflow.com/questions/7213549/long-polling-http-streaming-general-questions/7347851#7347851">Long轮询/ HTTP流一般问题
  • phpwebsocket
  • 在github
  • PHP-的WebSocket
  • 棘轮
  • 如何在PHP 实施彗星 - 经常挂引导
  • Long Polling/HTTP Streaming General Questions
  • phpwebsocket
  • php-websocket on github
  • Ratchet
  • how to implement comet in PHP - frequently linked to guide

一般当建立一个实时的基础设施已经从Web应用程序分离推送解决方案的最佳实践(注:node.js的和socket.io改变这个有点,但我个人还是觉得应该去耦的)。但是,假设后者仍然是你需要编写/主机/安装此推动解决方案的最佳解决方案。去耦也意味着技术并不一定是PHP,但您可以接入/从PHP使用它。也许有点矫枉过正?特别是如果你没有的太多的在您的网站的用户?

General best practice when building a realtime infrastructure has been to decouple the push solution from your web application (Note: node.js and socket.io has changed this a bit, but personally I still think it should be decoupled). But, assuming that the latter is still the best solution you would need to write/host/install this push solution. Decoupling also means that the technology doesn't have to be PHP but you can access/use it from PHP. Maybe a bit of overkill? And especially if you don't have too many users on your site?

为了简单起见,我建议考虑使用第三方托管服务。我为这样一个公司叫工作。使用服务像我们这样可以让你不再需要安装和维护应用程序的实时部分。这也使得它可以很容易地添加你正在​​寻找的推送功能。所有你需要做的是PHP的code几行添加到现有的应用程序,以触发推送通知,并添加了几行JavaScript到您的前端。

For simplicity I would recommend looking at using a 3rd party hosted service. I work for one such company called Pusher. Using a service such as ours lets you remove the need to install and maintain the realtime part of your application. It also makes it really easy to add the push functionality you are looking for. All you need to do is add a few lines of PHP code to your existing app to trigger the push notifications and add a few lines of JavaScript to your front-end.

资源:

  • 最常见的使用PHP库这样的:<一href="https://github.com/pusher/pusher-php-server">https://github.com/pusher/pusher-php-server
  • 快速入门指南
  • Most commonly use PHP library for this: https://github.com/pusher/pusher-php-server
  • Quickstart guide

如果你想调查的替代品或一些我上面提到的,我维护的实时技术列表,你也可能会感兴趣。

If you'd like to investigate the alternatives or some of the technologies I've mentioned above I'm maintaining a list of realtime technologies which you might also be interested in.

这篇关于Ajax的推送系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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