Most of the discussions on node. JS focus on dealing with high concurrency capabilities, making sure to identify the tradeoffs within node and the reasons for node application performance.
Node introduces a complex concept to javascript: The concurrency of shared state.
Node uses a long-running process
and PHP will produce multiple processes in Apache.
For example, as seen in :
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, it can be seen that after the application of PHP running, the next run will again apply for a new thread. Each run 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 exists, each execution will be added one, so there will be 1 2 3 4 5 6 ...
The new thread generated by Apache will refresh every time, $i will be assigned again, and node will not, and will give $i 1 each time. Therefore, you need to be especially careful when you change the variables in memory for the callback function in node.