Home > Article > Backend Development > childhoodmemory uses the PHP function memory_get_usage to obtain the amount of PHP memory cleared
1. Function prototype
int memory_get_usage ([ bool $real_usage = false ] )
2. Version compatible
PHP 4 >= 4.3.2, PHP 5
3. Basic usage and examples
1. Get the current memory consumption
Copy code The code is as follows:
echo memory_get_usage();
$var = str_repeat("liuhui", 10000);
echo memory_get_usage();
unset($var);
echo memory_get_usage();
?>
Copy code The code is as follows :
function convert($size){
$unit=array('b','kb','mb','gb','tb','pb');
return @ round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
}
echo convert(memory_get_usage(true)) ;
?>
Copy the code The code is as follows:
function array_size($arr) {
ob_start();
print_r($arr);
$mem = ob_get_contents();
ob_end_clean();
$mem = preg_replace("/n +/", "", $mem);
$mem = strlen ($mem);
return $mem;
}
$memEstimate = array_size($GLOBALS);
?>
The above introduces the childmemory method of using the PHP function memory_get_usage to obtain PHP memory clearing consumption, including the content of childmemory. I hope it will be helpful to friends who are interested in PHP tutorials.