Home > Article > Backend Development > php check how much memory is used
The method memory_get_usage refers to the memory currently being used by the script
unset just marks the memory as free but does not release it. It will be released after the GC program ends
$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);
[Recommended course: PHP video tutorial】
The above is the detailed content of php check how much memory is used. For more information, please follow other related articles on the PHP Chinese website!