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 ("127.0.0.1");
when using a browser to request these two addresses
php will always output 1
node. JS Outputs 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 a variable requests memory, is assigned 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, and therefore will appear 1 2 3 4 5 6. .
Apache generates new threads each time the state is refreshed, $i will be re-assigned,
node does not, every time will give $i plus 1
Therefore, node, you need to modify the callback function in memory variables in particular care.