php - How do I get the maximum allowed RAM usage in *bytes* at runtime?

one text

Solution:

function conv2bytes($val) {
    $val = strtolower(trim($val));

    $unit = substr($val,-1, 1);
    $val = substr($val, 0, -1);

    if($unit=='g') $val *= 1024*1024*1024;
    else if($unit=='m') $val *= 1024*1024;
    else if($unit=='k') $val *= 1024;
    else return false;
    return $val;
}

And use the code below to get the ram usage

echo memory_get_usage(false); // only the used memory is reported
echo memory_get_usage(true); // get total memory allocated from system, including unused pages

Reference: https://www.php.net/manual/en/function.memory-get-usage.php

Source