Home > Backend Development > PHP Tutorial > php check how much memory is used

php check how much memory is used

little bottle
Release: 2023-04-05 21:28:01
forward
3102 people have browsed it

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);
Copy after login

[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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template