帮助使用 PHP 和 Apache 创建流式(或推送)API [英] Help creating a streaming (or push) API with PHP and Apache

查看:16
本文介绍了帮助使用 PHP 和 Apache 创建流式(或推送)API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我正在从事的项目创建一个 API,允许开发人员创建围绕其功能构建的桌面和移动应用程序.我一直想学习的一件事是创建一个无状态的推送通知系统,类似于 Twitter 的 Streaming API.

I'd like to create an API for a project I'm working on, allowing developers to create desktop and mobile applications built around its functionality. One thing I've always wanted to learn how to do is create a stateless, push notification system, similar to Twitter's Streaming API.

基本上,我希望能够实时或尽可能接近地通知用户数据的任何更改.我知道这在移动设备上可能很困难,这就是为什么可能会构建移动应用程序以定期检查更新以节省电池.但是,桌面应用程序不会有这个限制.我想避免让应用程序询问服务器是否有新信息,而是让服务器告诉应用程序有新数据.

Basically, I want to be able to notify users of any changes to the data in real time, or as close to it as possible. I know that this might be difficult on mobile devices, which is why mobile applications will probably be built to check for updates periodically, to save battery. However, desktop applications won't have that limitation. I'd like to avoid making the application ask the server if there is new information, and instead let the server tell the application that there is new data.

我的编程语言是 PHP,我的服务器是 Apache.如果我绝对必须,我可以切换到 Lighttpd 或 nginx,但这绝对是最后的手段,因为它需要对我现有的所有代码进行大量更改.

My programming language is PHP and my server is Apache. If I absolutely had to I could switch to Lighttpd or nginx, but that's an absolute last resort since it would require a lot of changes to all of my existing code.

我读过这篇文章:

http://www.zeitoun.net/articles/comet_and_php/start

并对其进行了测试,但不幸的是,我的浏览器一直在尝试加载页面,但从未真正显示时间.我怀疑这是因为,无论出于何种原因,我一直无法让输出缓冲在我的服务器上工作,除非我发送 64kb(或更多)的数据.我听说我必须禁用 gzip,我做了,但它仍然不起作用,所以我不知道.

And tested it out, but unfortunately all that happens is my browser keeps attempting to load the page and never actually displays the time. I suspect this is because, for whatever reason, I've never been able to get output buffering to work on my server, unless I send 64kb (or more) of data. I heard that I had to disable gzip, which I did, and it still didn't work, so I don't know.

推荐答案

看看一些现有的技术来帮助你做到这一点:

Have a look at some existing technologies to help you do this:

龙卷风

Tornado 是可扩展、无阻塞的 Web 服务器和为 FriendFeed 提供支持的工具的开源版本.FriendFeed 应用程序是使用一个看起来有点像 web.py 或 Google 的 webapp 的网络框架编写的,但有额外的工具和优化来利用底层的非阻塞基础设施.

Tornado is an open source version of the scalable, non-blocking web server and tools that power FriendFeed. The FriendFeed application is written using a web framework that looks a bit like web.py or Google's webapp, but with additional tools and optimizations to take advantage of the underlying non-blocking infrastructure.

推动者

Pusher 是一种托管 API,可通过 WebSockets 将可扩展的实时功能快速、轻松、安全地添加到网络和移动应用程序.

Pusher is a hosted API for quickly, easily and securely adding scalable realtime functionality via WebSockets to web and mobile apps.

两者都非常快且可扩展,而且我都相对轻松地进行了设置.

Both are extremely fast and scalable, and I have setup both relatively easily.

这篇关于帮助使用 PHP 和 Apache 创建流式(或推送)API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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