|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-06-08 08:36 UTC] sailormax at inbox dot lv
[2018-02-28 21:57 UTC] cmb@php.net
-Package: Unknown/Other Function
+Package: PHP options/info functions
[2021-09-08 16:15 UTC] cmb@php.net
-Status: Open
+Status: Feedback
-Assigned To:
+Assigned To: cmb
[2021-09-08 16:15 UTC] cmb@php.net
[2021-09-19 04:22 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 07:00:01 2025 UTC |
Description: ------------ I did some memory tests to compare PHP 7.0.0RC2 (TS, 64bit) with 5.x versions and realized a strange behavior when using memory_get_usage() with $real_usage set to TRUE. I did a first call of memory_get_usage(true), produced some data and did a second call of memory_get_usage(true), before using the data. Then I compared the logged memory consumption. In the example below I got a memory difference of about 78 MB when calling the script the first time, the next time I called the script I got about the half of this value, and further calls reduced it more and more until I got to 0 bytes between the first and second call of memory_get_usage(true). After a restart of the web server (Apache 2.4) I get the same behavior again. NOTE: $real_usage set to FALSE works as expected. Test script: --------------- <?php $oldMem = memory_get_usage(true); $array = array(); for ($i=1; $i <= 10000; $i++) { $array[$i] = range(1, 96); } $newMem = memory_get_usage(true); echo "Array size: " . count($array) . "<br>"; echo "Memory consumption BEFORE: " . $oldMem . "<br>"; echo "Memory consumption AFTER: " . $newMem . "<br>"; Expected result: ---------------- Result of the first 10 calls after the restart of the web server: Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Actual result: -------------- Result of the first 10 calls after the restart of the web server: Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 83886080 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 44040192 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 23068672 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 12582912 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 8388608 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 6291456 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 4194304 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 4194304 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 4194304 Array size: 10000 Memory consumption BEFORE: 2097152 Memory consumption AFTER: 2097152