简体   繁体   English

PHP和Node.js还是只有Node.js?

[英]PHP and Node.js or only Node.js?

I want to write a simple chat application (for test use). 我想写一个简单的聊天应用程序(供测试使用)。

The users and messages are getting persisted in MongoDB, the session are getting stored with Redis. 用户和消息在MongoDB中持久存在,会话将与Redis一起存储。

The PHP (Symfony2) is providing authentication, registration, passwort reset, etc. and serves the public site (like /, /contact, etc.). PHP(Symfony2)提供身份验证,注册,密码重置等,并为公共站点提供服务(如/,/ contact等)。

When the user has logged it has controll to the chat application. 当用户登录时,它具有对聊天应用程序的控制权。 Backbone.js handles the application and node.js provides the data through rest (or socket.io). Backbone.js处理应用程序,node.js通过rest(或socket.io)提供数据。

Should I use either PHP and Node sidebyside or should I only use node? 我应该使用PHP和Node sidebyside还是我应该只使用节点?

The pro of only using node would be that there are no port collisions the contra is that the node app gets quite big and not so readable (IMHO: cmf, registration, authorisation, email handling would be easier to do with symfony than node) 仅使用节点的专家将是没有端口冲突,因为节点应用程序变得非常大而且不那么可读(恕我直言:cmf,注册,授权,电子邮件处理对于symfony比节点更容易)

It totally makes sense to keep your web application logic in PHP. 将您的Web应用程序逻辑保留在PHP中是完全有意义的。 That's what PHP is good at, and porting it to node.js code would probably be a wasteful and painful experience. 这就是PHP擅长的,将它移植到node.js代码可能是一种浪费和痛苦的经历。

Node on the other hand is good at networking and serving long-running connections, such as WebSockets (socket.io, SockJS, etc.). 另一方面,节点擅长网络连接和长期连接,例如WebSockets(socket.io,SockJS等)。 So having a chat server using that also makes sense. 因此,使用聊天服务器也是有意义的。

I suggest you use both, since each one of them solves a specific problem that it's good at. 我建议你同时使用它们,因为它们中的每一个都解决了它擅长的特定问题。 You can easily connect them using some kind of message queue. 您可以使用某种消息队列轻松连接它们。

You can try using JooDee, a node webserver which allows you to embed serverside javascript in your web pages. 您可以尝试使用JooDee,这是一个节点网络服务器,允许您在网页中嵌入服务器端javascript。 If you are familiar with Node and PHP/ASP, it is a breeze to create pages. 如果您熟悉Node和PHP / ASP,那么创建页面就是轻而易举的事。 Here's a sample of what a page looks like below: 以下是页面如下所示的示例:

<!DOCTYPE html>
<html>
<:  //server side code in here
    var os = require('os');
    var hostname = os.hostname();
:>
<body>
    <div>Your hostname is <::hostname:></div>
</body>
</html>

Using JooDee also lets you expose server javascript vars to the client with no effort by attaching attributes to the 'Client' object server side, and accessing the generated 'Client' object in your client side javascript. 使用JooDee还可以让您通过将属性附加到“客户端”对象服务器端,并在客户端javascript中访问生成的“客户端”对象,将服务器javascript变量公开到客户端。

https://github.com/BigIroh/JooDee https://github.com/BigIroh/JooDee

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM