The vast majority of the discussions on node. JS focus on dealing with high concurrency capabilities, making sure to understand the tradeoffs within node and the reasons for the good performance of node applications.
Node introduces a complex concept to javascript: The concurrency of shared state.
Node takes a long-running process
and PHP will produce multiple processes in Apache.
As shown in the following:
Code Validation:
Php:
<?php$i = 0; $i ++;echo $i
Nodejs
var http = require (' http '); var i=0;http.createserver (function () { i++ console.log (i) }). Listen (3000, ' 127.0.0.1 ');
When using a browser to request these two addresses, PHP will always output 1node.js will output 1 2 3 4 5 6 ... Through the picture, you can see that after PHP executes the program, the next execution will reapply for a new thread. Each execution of the variable will request memory, assign a value of 0, plus 1, so the output is 1 and Nodejs will maintain a long-running process, the variable i in memory always exists, each execution will be added one, so there will be 1 2 3 4 5 6 ...
The new threads generated by Apache will be refreshed each time, $i will be re-assigned, and node will not, and will give $i 1 each time. Therefore, in node, you need to be very careful about modifying the memory variables in the callback function.