Skip to content

Instantly share code, notes, and snippets.

@real34
Created November 1, 2011 06:59
Show Gist options
  • Save real34/1330072 to your computer and use it in GitHub Desktop.
Save real34/1330072 to your computer and use it in GitHub Desktop.
PHP : A simple function to display the current memory usage
<?php
// @see http://fr2.php.net/manual/en/function.mb-convert-encoding.php#103300
function memory_usage() {
$mem_usage = memory_get_usage(true);
if ($mem_usage < 1024) {
$mem_usage .= ' bytes';
} elseif ($mem_usage < 1048576) {
$mem_usage = round($mem_usage/1024,2) . ' kilobytes';
} else {
$mem_usage = round($mem_usage/1048576,2) . ' megabytes';
}
return $mem_usage;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment