Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

memory_get_usage

Description

The memory_get_usage of Options / Information for PHP returns the amount of memory allocated to PHP.

Syntax

memory_get_usage(bool $real_usage = false): int

Parameters

real_usage

Set this to true to get total memory allocated from system, including unused pages. If not set or false only the used memory is reported.

Return

Returns the memory amount in bytes.

Examples

1 · void

<?

$return = memory_get_usage();

echo $return;

?>
409056

2 · real_usage

<?

$real_usage = true;

$return = memory_get_usage($real_usage);

echo $return;

?>
2097152

3

<?

echo memory_get_usage() . PHP_EOL;

$str_repeat = str_repeat("repeat", 1000);

echo memory_get_usage() . PHP_EOL;

unset($str_repeat);

echo memory_get_usage();

?>
409744
417936
409744

4

<?

function bytes($size)
{
    $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
    
    return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2) . $unit[$i];
}

$real_usage = true;

$return = memory_get_usage($real_usage);

echo bytes($return);

?>
2mb
HomeMenu