laravel Node.js + Angular + Redis + Socket.io 堆栈有什么好处?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30976683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are the benefits for the Node.js + Angular + Redis + Socket.io stack?
提问by funguy
I have tried this tutorial:
我试过这个教程:
http://kodeinfo.com/post/realtime-app-using-laravel-nodejs-angularjs-redis
http://kodeinfo.com/post/realtime-app-using-laravel-nodejs-angularjs-redis
which in short is building a real time app by using Node.js + Angular + Redis + Socket.io + Laravel (PHP as a backend).
简而言之,就是使用 Node.js + Angular + Redis + Socket.io + Laravel(PHP 作为后端)构建一个实时应用程序。
The question that is bugging me is why try to leverage all of these technologies just to implement a real time feature? Are there any more benefits to using this (Node.js + Angular + Redis + Socket.io) stack over, lets say, simple AJAX call to the backend? For what other use cases you have used this stack?
困扰我的问题是为什么要尝试利用所有这些技术来实现实时功能?使用这个(Node.js + Angular + Redis + Socket.io)堆栈是否还有更多好处,比如对后端的简单 AJAX 调用?您在哪些其他用例中使用了此堆栈?
回答by Dory Zidon
Each of the technologies you've listed is not required for real-time, however I think you might find it useful to get further understanding of each technology and it use.
您列出的每项技术都不是实时必需的,但是我认为您可能会发现进一步了解每项技术及其使用会很有用。
Each technology has it's advantages and usages. I would suggest you do some more in-depth reading on each technology separate. You can always use just ajax but you're missing out on a lot of the advantages of each technology. All of these are highly tested, DRY and componentize, meaning you'll prob be productive quicker and re-invest less of the wheel.
每种技术都有其优点和用途。我建议您对每种技术分别进行更深入的阅读。您总是可以只使用 ajax,但您会错过每种技术的许多优点。所有这些都经过高度测试、DRY 和组件化,这意味着您可能会更快地提高生产力并减少再投资。
Furthermore these technologies tend to work really well together, and are based on many similar concepts.
此外,这些技术往往可以很好地协同工作,并且基于许多相似的概念。
1) Node.js - you'll need some backend technology for sure, you can use php, node.js or whichever you prefer. However node.js has some clear advantages. Aside from being JavaSript, so you can share code, and node.js non-blocking i/o allowing you to use more resources.
1) Node.js - 你肯定需要一些后端技术,你可以使用 php、node.js 或任何你喜欢的。然而,node.js 有一些明显的优势。除了是 JavaSript,您可以共享代码,并且 node.js 非阻塞 i/o 允许您使用更多资源。
2) Angular - angular is your front-end mvc. There are many frameworks (Ember, Backend and many others). you can pick anyone or pick none, however this is not instead of Ajax. There framework bring loads more such is two way data-binding, components, data layer and so much more. again great building blocks to build a high impact professional app.
2) Angular - angular 是你的前端 mvc。有许多框架(Ember、Backend 和许多其他框架)。您可以选择任何人或不选择任何人,但这不能代替 Ajax。框架带来了更多的负载,例如两种方式的数据绑定、组件、数据层等等。再次构建具有高影响力的专业应用程序的重要构建块。
3) Redis is a nosql database. Real-time has very little to do with it, however it can be used for that. However it has been used for many pub-sub implementation to maintain state across instances / clients. Have a read about Redis
3)Redis是一个nosql数据库。实时与它几乎没有关系,但是它可以用于此目的。然而,它已被用于许多发布-订阅实现以跨实例/客户端维护状态。阅读有关 Redis 的内容
4) Socket.io - This is the most real-time oriented component and the main one you might actually "replace" with Ajax. I would strongly urge you, than even if you decide not to use any one of the other component, you still use socket.io/another socket library. Socket.io provide browsers / servers with a socket like interface (similar to winsock on windows). Meaning browser can send and receive messages. Just FYI socket relies heavily on Ajax, however it simplifies the usage and does not require you yourself to main the connection state, handles browser inconsistencies and much more. While you could potentially write faster code using plain Ajax, more chances are you'd end up introducing more issues...However it's your call :)
4) Socket.io - 这是最面向实时的组件,也是您实际上可能会用 Ajax “替换”的主要组件。我强烈建议你,即使你决定不使用任何其他组件,你仍然使用 socket.io/another socket library。Socket.io 为浏览器/服务器提供类似套接字的接口(类似于 windows 上的 winsock)。意思是浏览器可以发送和接收消息。仅供参考,socket 严重依赖 Ajax,但它简化了使用,不需要您自己维护连接状态,处理浏览器不一致等等。虽然您可以使用普通的 Ajax 编写更快的代码,但最终引入更多问题的可能性更大……但是这是您的要求:)