CKTIS / PHP
memory_get_usage()
Read the current number of bytes used by PHP’s memory manager.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
memory_get_usage(bool $real_usage = false): intRead the current number of bytes used by PHP’s memory manager. The default counts active allocations. With true it also includes unused pages acquired from the system. The result excludes allocations made outside the PHP memory manager.
Signature
memory_get_usage(bool $real_usage = false): int
Example output
[true,true,1048576]
Examples
<?php
$before=memory_get_usage(); $buffer=str_repeat("p", 1024*1024); $used=memory_get_usage();
echo json_encode([$used>$before,memory_get_usage(true)>=$used,strlen($buffer)]);
Result
[true,true,1048576]