Saturday 3 June 2017

Is node.js or django "request driven" like PHP?

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\sessions) and once the script is done it is done.

While reading about Node'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.



via Booshe99

No comments:

Post a Comment