php5.2.0 memory management improvements_PHP tutorial

WBOY
Release: 2016-07-21 15:57:42
Original
851 people have browsed it

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.
To test 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 code The code is as follows:

echo '1>>';
sleep(5);

$o = array();
for ($i=0;$i<=100000;$i++) {
$o[]='aaaaaaaaaaaaaaaaaaaaa';
}
echo '2>>';
sleep(5);

unset($o);
echo '3>>';
while (true) {
echo '..';
sleep(10);
}
?>
Bash script to monitor memory usage (note: " inside mem" is taken from the php script name above):

while true;do clear;ps au|grep -v "(vi|grep)"|grep "(mem|RSS)";sleep 2; done;
The following is the $/usr/local/bin/php mem.php process 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) RSS (memory usage value, unit KB) results of the test.

php5.1.6:
3164
18076
17572

PHP5.2.0:
4088
14400
4424
You can watch it As of version 5.1.6, after unsetting the array, the memory is not released from the process. Although it can continue to be reused by the php process, it 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. This 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 block requested from the system ( blocks). 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).

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317766.htmlTechArticleThe memory management of php5.2.0 has been greatly improved. In some cases, the problem of memory not being released does not exist. . Testing the php script (mem.php), I use echoN and sleep to control the script to pause at a certain stage...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!