方法memory_get_usage 是指當前腳本正在使用的內(nèi)存
unset只是把內(nèi)存標記為空閑但并沒有釋放,要GC程序結(jié)束后才會釋放
- $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);
新聞熱點
疑難解答