我已经使用 PHP 和 mySQL 作为后端构建了多个网站,并且相信我对两者都相当熟悉。然而,在研究我的新网站时,我遇到了 node.js 和 mongodb(以及 socket.io,因为该网站将包含聊天)。
我决定使用 node.js 和 mongodb 来运行聊天 - 但不知道我是否应该只用这两件事来做整个网站? 既然我要运行一个 Node 服务器,我应该只运行另一个(单独的)一个托管网站的服务器吗?或者这是一个坏主意? - 稳定吗? 我可以在 PHP 中进行编程并且仍然使用 mongodb - 但 Node 不会更快吗?
还有一个问题: 我计划使用 ajax 来处理页面上的所有帖子 - 但由于我已经使用 socket.io 进行聊天 - 我应该使用它来完成我的所有帖子请求吗? 对于 ajax,我计划使用 jQuery(也适用于所有前端效果)。
最佳答案
don't know if I should just do the entire site with those two things?
如果你想学习 node.js,没有什么比编码更好的了。
Since I'm gonna run a node server anyway should I just run another (seperate) one hosting the website?
您可以使用现有服务器并在其他空闲端口(o)上运行您的 node.js 应用程序。我认为学习 Node 不需要专用机器。
is it stable?
即使是 node.js 的版本也是稳定的版本,但是在 1.0 版本卡住之前,它的 API 可能会发生重大变化。
I could do the programming in PHP and still be using mongodb - but wouldn't node be way faster?
它很可能(并且肯定)会。
I've planned to use ajax to handle all the posts to the page - but since I'm allready using socket.io to the chat - should I do all my post request using that?
我建议坚持 MVC 模型并使用 express,因为如果您将 socket.io 用于经典内容,您可能会遇到很多耗时的问题。 Socket.io 就是用于实时功能和与之相关的东西。
https://stackoverflow.com/questions/5904732/