node.js或django是否像PHP一样“请求驱动”?(Is node.js or django “request driven” like PHP?)
说实话,我是一名Linux管理员,几年后还没有完成Web开发。 LAMP是我制作过去10年以上任何网络的首选工具。
我正在研究REST API,我正在考虑扩展。 我知道有很多方法可以用PHP做REST,但也许这不是最好的方法。
就我而言,PHP模型是这样的:
用户在浏览器中发出请求(或AJAX调用) PHP被调用了。 PHP从顶部开始,按顺序向下运行,连接到数据库,运行查询,执行操作和输出数据。 请求结束,用户拥有他们的数据并准备创建一个新数据。使用PHP,每个请求都是新的交易。 没有共享变量(您可以使用cookies \ sessi传递内容),一旦脚本完成,它就完成了。
在阅读ode的架构时,似乎所有内容都在这个单线程事件循环中运行。 这是否意味着节点“始终在运行”,您可以在请求之间共享变量,还是每个请求都有一个新的事件循环? 这是否意味着您可以编写草率代码来阻止节点接受来自其他随机用户的新请求? Django的运作方式是否类似? 如果是这种情况,是否可以为每个请求生成新的节点进程?
这看起来很危险。 在PHP中,您可以编写草率代码,导致单个请求运行缓慢,但每个请求都是独立的(系统资源允许)。 我也喜欢PHP的“脚本和终止”性质,但也许这只是一种旧式的思维方式。
我将有一个电话app \ website,它可以来回传递数据到API以从数据库中获取信息(想想库存管理工具)。 我已经明确定义了API调用,前端开发人员只需根据需要调用它们。 我有各种调用来获取各种数据。
To be honest I'm a Linux admin and haven't done web development in a few years. My tool of choice for making anything web of the past 10+ years has been LAMP.
I'm working on a REST API and I'm thinking of branching out. There are ways to do REST in PHP I know but maybe it's not the best way anymore.
The PHP model as far as I'm concerned goes like this:
User makes request in their browser (or an AJAX call) PHP get's called up. PHP starts at the top and works it's way sequentially to the bottom, connecting to the DB, running queries, doing stuff, and outputting data. Request is over, the user has their data and is ready to make a new one.With PHP each request is a new deal. There are no shared variables (you can pass things with cookies\sessi) and once the script is done it is done.
While reading about ode's architecture it seems as if everything runs in this single threaded event loop. Does that mean node is "always running" and you can share variables between requests or is there a new event loop per request? Does that mean you can write sloppy code to block node from accepting new requests from other random users? Does Django operate similar? If that is the case is it possible to spawn new node processes per request?
That seems kind dangerous. In PHP you can write sloppy code that causes the single request to run slow but each request is kind of independent (system resources permitting). I also like the "do script and terminate" nature of PHP but maybe that is just an old school way of thinking.
I'm going to have a phone app\website that passes data back and forth to an API to get information from a database (think an inventory management tool). I have clearly defined API calls and a front end dev just calls them as needed. I have various calls to get various bits of data.
最满意答案
在阅读ode的架构时,似乎所有内容都在这个单线程事件循环中运行。 这是否意味着节点“始终在运行”,您可以在请求之间共享变量,还是每个请求都有一个新的事件循环?
是的,node.js是一个始终运行的单线程。 它是一个处理您的请求并发送响应的循环。 与LAMP设置相比:node.js是apache和php在一起。
这是否意味着您可以编写草率代码来阻止节点接受来自其他随机用户的新请求?
是的,它确实。 您可以在请求之间共享状态,并且可以阻止其他请求,更糟糕的是,您可以完全终止该进程,或向其他用户显示一些个人数据。 使用node.js有很多方法可以用脚射击自己。 但另一方面,您可以在node.js中编写出的高效应用程序,并且您可以从不需要为每个请求重新启动整个应用程序的事实中获得很多性能。
While reading about ode's architecture it seems as if everything runs in this single threaded event loop. Does that mean node is "always running" and you can share variables between requests or is there a new event loop per request?
Yes, node.js is a always running single thread. Its a loop that handles your requests and sends out respes. Compared to a LAMP setup: node.js is apache and php together.
Does that mean you can write sloppy code to block node from accepting new requests from other random users?
Yes, it does. You can share states between requests and you can block other requests, even worse you can kill the process completely, or display some personal data to other users. There are quite a few ways to shoot yourself in the foot with node.js. But on the other hand you can write terrific efficient applicati in node.js and you can gain a lot of performance from the fact that you don't need to restart your whole app for every single request.
#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格
推荐阅读
留言与评论(共有 13 条评论) |
本站网友 雷火炙 | 6分钟前 发表 |
我有各种调用来获取各种数据 | |
本站网友 驼峰鼻矫正术价格 | 10分钟前 发表 |
但也许这不是最好的方法 | |
本站网友 洛东小区二手房 | 9分钟前 发表 |
您可以在请求之间共享状态 | |
本站网友 于都信息 | 18分钟前 发表 |
PHP从顶部开始 | |
本站网友 股指期货培训 | 26分钟前 发表 |
但每个请求都是独立的(系统资源允许) | |
本站网友 神舟a400 | 24分钟前 发表 |
您可以完全终止该进程 | |
本站网友 浦东租房网 | 25分钟前 发表 |
它是一个处理您的请求并发送响应的循环 | |
本站网友 车辆交强险 | 0秒前 发表 |
与LAMP设置相比:node.js是apache和php在一起 | |
本站网友 phpproxy | 22分钟前 发表 |
我也喜欢PHP的“脚本和终止”性质 | |
本站网友 恶魔无双 | 18分钟前 发表 |
您可以完全终止该进程 | |
本站网友 证券分析师的最佳实践指南 | 5分钟前 发表 |
使用node.js有很多方法可以用脚射击自己 | |
本站网友 淘金家园 | 26分钟前 发表 |
这是否意味着您可以编写草率代码来阻止节点接受来自其他随机用户的新请求? 是的 |