Skip to content

Instantly share code, notes, and snippets.

@LeonSkrilec
Created April 15, 2019 11:38
Show Gist options
  • Save LeonSkrilec/0e877e5a5fafd6d42d2bc8096f54abfd to your computer and use it in GitHub Desktop.
Save LeonSkrilec/0e877e5a5fafd6d42d2bc8096f54abfd to your computer and use it in GitHub Desktop.
PHP peak memory usage
memory_get_peak_usage();
function formatBytes($bytes, $precision = 2) {
$units = array("b", "kb", "mb", "gb", "tb");
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= (1 << (10 * $pow));
return round($bytes, $precision) . " " . $units[$pow];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment