The memory management of php5.2.0 has been greatly improved, and the problem of memory not being released in some cases no longer exists.
Testing the php script (mem.php), I use echo N>> and sleep to control the script to pause at a certain stage to detect the status.
Copy the code The code is as follows:
echo '1>>';
sleep(5);
$o = array();
for ($i=0;$ i<=100000;$i++) {
$o[]='aaaaaaaaaaaaaaaaaaaa';
}
echo '2>>';
sleep(5);
unset($o);
echo '3& gt;> ';
while (true) {
echo '..';
sleep(10);
}
?>
bash script to monitor memory usage (note: the "mem" inside is taken from the php above Script name):
while true;do clear;ps au|grep -v "(vi|grep)"|grep "(mem|RSS)";sleep 2;done;
The following is $/usr/local/bin/ php mem.php process is in three states (before array creation, after array creation, after array destruction), using PHP 5.1.6 and 5.2.0 (I used the same configure parameters) to test RSS (memory usage) Value, unit KB) result.
php5.1.6:
3164
18076
17572
PHP5.2.0:
4088
14400
4424
You can see that in version 5.1.6, after unset the array, the memory is not released from the process, although it can It continues to be reused by this php process, but cannot be used by other processes in the system. And 5.2.0 really frees up memory.
You may also notice that at the beginning, the memory usage of 5.2.0 was a few kb more than that of 5.1.6. This is due to the addition of some new things in 5.2.0, which is normal.
In addition, the memory allocation of php5.2.0 has also been greatly improved. The official statement is that the detection of memory_limit is changed from each time emalloc() is called to directly detecting the memory data blocks (blocks) requested from the system. Friends who need to know more can study the code themselves. Due to changes in the implementation of memory allocation, memory control can be more accurately controlled under memory_limit. That is to say, in the previous PHP code, if there was memory usage that exceeded memory_limit without errors, it may be in PHP5.2.0 Report an error. In order to balance this improvement, the default memory_limit of PHP5.2.0 has been changed from the previous 8MB to 16MB. Searching the source code can see this modification (find . -name *c -type f |xargs cat |grep memory_limit).
The above introduces the memory management improvements of thinkpad e520 php520, including the content of thinkpad e520. I hope it will be helpful to friends who are interested in PHP tutorials.