duanmajing9332 2010-10-24 22:20
浏览 36
已采纳

PHP memory_get_usage

I came across the PHP's memory_get_usage() and memory_get_peak_usage().

The problem is that I found that these two functions do not provide the real memory used by the current script. My test script is:

<?php

echo memory_get_usage();

echo '<br />';

$a = str_repeat('hello', 100000);

echo '<br />';

echo memory_get_usage();

echo '<br />';

echo memory_get_peak_usage();

?>

Which returns:

355120

5355216

5356008

What do you understand from this?

The first value is before executing the str_repeat() so it has to be the value of 0.

The second is after the process and it's OK to have a value greater than 0 but not that big value.

The third is the "peak" value and it's slightly greater than the second as I think it should be the biggest value in a processing microsecond.

So do you think that the real value of the current script's memory consumption should be like this:

memory_usage = the second memory usage - the first memory usage

peak_memory_usage = the third (peak_usage) - the first memory usage

which gives:

1) 5355216 - 355120 = 5000096 bytes

2) 5356008 - 355120 = 5000888 bytes

If this is how it works, I assume that the first 355120 bytes are the whole system allocated memory used by apache and other modules, as the first value never changes when you increase or decrease the number of repeats in the str_repeat(), only the two values after the process increase or decrease but never gets smaller that the first value.

  • 写回答

3条回答 默认 最新

  • dragon071111 2010-10-24 22:24
    关注

    According to the php manual, memory_get_usage returns the amount of memory allocated to php, not necessarily the amount being used.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题