方法memory_get_usage 是指當前腳本正在使用的內存
unset只是把內存標記為空閑但並沒有釋放,要GC程序結束后才會釋放
$bytes = 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];
}
echo formatBytes($bytes);
