使用 PHP 创建实时网站
我目前正在使用 PHP 和 Kohana 框架创建一个网站。我希望网站能够使用实时(或接近实时)数据(例如用于聊天和实时提要)。我需要它能够扩展到数千个并发用户。我读了很多书,但仍然不知道最好的方法是什么。
有人有使用 StreamHub 的经验吗?可以用 PHP 来使用它吗?
我是不是给自己挖了个坑,需要切换语言?我研究过 Node js 和 nowjs,但我厌倦了在 Express 中编写 while 站点(我想知道安全漏洞、代码可维护性、缺乏良好的 ORM)。我读过有关 Twisted Python 的内容,但不知道哪种 Web 框架可以在此基础上很好地工作,而且我不想使用 Nevow - 也许 Django 可以很好地与 Twisted Python 一起使用?我只是希望找到正确的方向,所以我不会在 PHP 中走得太远,并意识到我无法获得我需要的近乎实时的结果。
感谢您的帮助。
I'm currently creating a website using PHP and the Kohana framework. I want to site to be able to use real time (or near real time) data (e.g. for chat and real time feeds). I need it to be able to scale to thousands of concurrent users. I've done a lot of reading and still have no idea what the best method is for this.
Does anyone have any experience with StreamHub? Is it possible to use this with PHP?
Am I digging myself into a hole here and need to switch languages? I've looked at node js and nowjs, but I'm weary about coding a while site in Express (I wonder about security holes, code maintainability, lack of a good ORM). I've read about Twisted Python, but have no idea what web framework would work well on top of that, and I'd prefer not to use Nevow - maybe Django can be used well with Twisted Python? I'm just looking to be pointed in the right direction, so I don't go too far in PHP and realize I can't get the near real-time results that I need.
Thanks for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你会 JavaScript,我个人可以保证代码的可维护性。我个人认为 JavaScript 比 PHP 更易于维护,但这可能是由于缺乏 PHP 经验。
ORM 不是问题,因为 Node.js 更喜欢基于文档的数据库。基于文档的数据库和 JSON 齐头并进,我发现 couch db 及其 Map/Reduce 系统易于使用,并且使用 json 感觉很自然。
就安全漏洞而言,是的,node.js 服务器还很年轻,可能存在漏洞。这些都是无法避免的。目前还没有已知的漏洞,我想说它并没有更容易受到攻击
然后是 IIS/apache/nginx 直到有人指出一个大缺陷。
这样的可扩展性需要非阻塞 IO。这需要一个非阻塞 IO 服务器,如 nginx 或 node.js(是的,阻塞 IO 可以工作,但你需要更多的硬件)。
就我个人而言,我建议使用node.js而不是PHP,因为在node中编写非阻塞IO更容易。您可以使用 PHP 完成此操作,但必须做出所有正确的设计和架构决策。我怀疑是否存在真正的异步非阻塞 PHP 框架。
Python 的扭曲/Ruby 的 EventMachine 与 nginx 一起可以工作,但我对这些没有专业知识。至少使用 Node,您不会意外调用阻塞库或使用本机阻塞库,因为 JavaScript 没有本机 IO。
I can personally vouch for code maintainability if you can do JavaScript. I personally find JavaScript more maintainable then PHP but that's probably due to lack of PHP experience.
ORM is not an issue as node.js favours document based databases. Document based databases and JSON go hand in hand, I find couch db and it's map/reduce system easy to use and it feels natural with json.
In terms of security holes, yes a node.js server is young and there may be holes. These are un avoidable. There are currently no known exploits and I would say it's not much more vulnerable
then IIS/apache/nginx until someone points a big flaw.
Scalability like that requires non-blocking IO. This requires a non-blocking IO server likes nginx or node.js (Yes blocking IO could work but you need so much more hardware).
Personally I would advice using node.js over PHP as it's easier to write non blocking IO in node. You can do it in PHP but you have to make all the right design and architecture decisions. I doubt there are any truly async non-blocking PHP frameworks.
Python's twisted / Ruby's EventMachine together with nginx, can work but I have no expertise with those. At least with node you can't accidentally call a blocking library or make use of the native blocking libraries since JavaScript has no native IO.
PHP 不是您应该用于网站实时更新的语言。 PHP 脚本先于 HTML 加载(HTML 调用 javascript 文件),因此 PHP 无法为您更新页面。但是,当与 AJAX 一起使用时(例如,使用 jQuery 函数调用 PHP 文件来实时更新页面),您可以以这种方式使用 PHP。
使用 jQuery 和 AJAX(全是 javascript),您可以在更新页面方面做很多事情,而无需重新加载它。我看过诸如 这个演示了如何使用 jQuery 进行聊天。
PHP is not the language you should be using for real-time updates of a website. PHP scripts load first before HTML (and HTML calls javascript files), so PHP cannot update your page for you. However, when used with AJAX (eg. using a jQuery function to call a PHP file to update your page in real-time), you can use PHP in this fashion.
Using jQuery and AJAX (all javascript), you can do quite a bit in terms of updating a page without reloading it. I've seen sites such as this one that demonstrate how to make a chat using jQuery.