Created
April 15, 2019 11:38
-
-
Save LeonSkrilec/0e877e5a5fafd6d42d2bc8096f54abfd to your computer and use it in GitHub Desktop.
PHP peak memory usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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