ThinkPad E520 php520 Memory management improvements

Source: Internet
Author: User
PHP5.2.0 's memory management has been greatly improved, and in some cases the problem of memory not being released does not exist.
Test PHP script (mem.php), I use echo n>> and sleep to control the script at some stage to detect the state of the pause.

Copy the Code code 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: the "mem" inside 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 this process in three states (array creation, after the array is created, after the array is destroyed), with 5.1.6 and 5.2.0 php (I used the same configure parameters) to test the RSS (Memory usage value, Unit KB) results.
php5.1.6:
3164
18076
17572
PHP5.2.0:
4088
14400
4424
As you can see in this version of 5.1.6, after the unset array, the memory is not freed from the process, although it can continue to be reused by this PHP process, but 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 very beginning, 5.2.0 's memory usage is a few kilobytes more than 5.1.6, which is normal because 5.2.0 adds something new.
In addition, php5.2.0 's memory allocation has also been greatly improved, the official argument is that the detection of memory_limit by each call Emalloc () is changed to directly detect the memory data block (blocks) from the system request. Friends who need a better understanding can study the code on their own. Because of the memory allocation implementation changes, memory control can be more precisely controlled under Memory_limit, that is, in the previous PHP code, if there is more than memory_limit memory usage without error, in php5.2.0 may error. To balance this improvement, PHP5.2.0 's default Memory_limit was changed from the previous 8MB to 16MB. The search source code can see this modification (find. -name \*c-type F |xargs cat |grep memory_limit).

The above describes the ThinkPad E520 php520 memory management improvements, including ThinkPad e520 aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.