Memory_get_usage--Returns the amount of memory currently assigned to your PHP script, in bytes (byte).
int Memory_get_usage ([bool $real _usage = false])
Real_usage
If set to TRUE, gets the total memory size of the system allocation, including unused pages. If not set or set to FALSE, only the amount of memory actually used is reported.
Basic usage and examples
1, gets the current memory consumption
<?php echo Memory_get_usage (); $var = Str_repeat ("Liuhui", 10000); Echo Memory_get_usage (); Unset ($var); Echo Memory_get_usage ();?>
Output separately: 62328 122504 62416
Description: The value of the Memory_get_usage () function output is bytes units
2, Format memory_get_usage () output
<?php function Convert ($size) {$unit =array (' B ', ' KB ', ' MB ', ' GB ', ' TB ', ' PB '), return @round ($size/pow (1024x768, ($i =floor (Log ($size, 1024)))), 2). ' '. $unit [$i]; } Echo Convert (Memory_get_usage (true));?>
Output: KB
3, Custom function get array or variable value size
<?php function Array_size ($arr) {Ob_start (); Print_r ($arr); $mem = Ob_get_contents (); Ob_end_clean (); $mem = Preg_repl Ace ("/\n +/", "", $mem); $mem = strlen ($MEM); return $mem; } $memEstimate = Array_size ($GLOBALS);?>