W
W
WebDev2019-02-04 14:04:58
Programming languages
WebDev, 2019-02-04 14:04:58

What is the difference between the way nodejs, python and php work?

Hello!
I began to study nodejs, before that I worked only with PHP and a little with Python from the server-side Java.
These technologies work a little differently, but I'm not sure if I understand everything correctly. I will explain with my fingers how I understood their work, and you, please correct me if I'm wrong.
So PHP and Python work in the same way: a request comes in and the web server transfers the execution of the request to the PL handler.
That is a script like this:

i = 1;

print(i);

i++;

It will output both in PHP and in Python 1. It (the script) will run anew each time, as if for the first time. And, it turns out that in this case, both of these languages ​​​​are created to die ?
In nodejs, unlike the above languages, something like an infinite loop is launched, and all incoming requests fall into it and are processed. And the pseudocode above would look like this:
i = 1;

server.on('connection', () => {
    print(i);

    i++;
});

And it will display different numbers for everyone.
That is, nodejs is specially made for just such a model of work. To work with "save state".
Theoretically, you can also make PHP work like nodejs, something like this:
$i = 1;

while (true) {
    $data = getData();//Каким-то образом принимать данные извне
    send(i);
    $++;
}

And run as a daemon.
But here it is problematic to organize interaction with this demon from the outside (and is it possible to do this? how?).
Bottom line: php and python run and "die", while nodejs "lives" until it is restarted or broken. Here I have another question: How do other EPs work? For example java on the server or go? What is their working model?
I would be very grateful for detailed answers.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pavlyuk, 2019-02-04
@pav5000

PHP, Python, NodeJS, Go, Java - they all know how to work as daemons, regularly.
And all of them can be made to work in the script run mode for each request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question