What does memory_get_peak_usage (true) do?

The PHP manual says:

int memory_get_peak_usage ([ bool $real_usage = false ] )

Returns the memory peak in bytes that has been allocated for your PHP script.

Options

real_usage

Set this to TRUE to get the actual size of the memory allocated from the system. If not set or FALSE, only the memory used by emalloc () is reported.

So, how is emalloc() not a real use, and how does TRUE calculate the use of real memory?

https://stackoverflow.com/questions/71053/... requests the same thing, but the only answer does not go into details about how the calculation is performed, except for rounding off some distributions by the next kilobyte.

A broader answer to what happens under the hood when you use FALSE and TRUE ?

+6
source share
1 answer

This question is a duplicate, as mentioned above.

However, I think I should summarize my understanding from different answers and comments:

  • memory_get_peak_usage(false) returns the exact memory used by the PHP script. Use a script to compare the exact memory consumption in different sections of PHP.
  • memory_get_peak_usage(true) returns the memory allocated from the system in a PHP script, it is always higher because the Zend engine allocates memory in 256 KB blocks. Use to find out the real impact of this PHP script on the system.

Basically, memory_get_peak_usage(true) should be memory_get_peak_usage(false) rounded to the next 256KB .

+3
source

Source: https://habr.com/ru/post/954182/


All Articles