You get a bonus - 1 coin for daily activity. Now you have 1 coin

How to check total and free server RAM in PHP

Practice




how to check total and free server RAM in PHP UNIX

function GetInfoMemory()
{
exec('free -mo', $MemoryInf);
preg_match_all('/s+([0-9]+)/', $MemoryInf[1], $matches);
list($total, $used, $free, $shared, $buffers, $cached) = $matches[1];
// echo "Memory: " . $used . "/" . $total;
$MemoryInfo=array($free,$total, $used );
return $MemoryInfo;
}


exec - if this is your own server or your host allows running this function.

Also note that PHP has built-in functions, but they only let you find out how much memory has been used or allocated for running the PHP script itself, i.e. not the total memory

memory_get_usage Returns the amount of memory, in bytes, that has been allocated to the PHP script so far.
memory_get_peak_usage() - Returns the peak amount of memory allocated to PHP
memory_limit the maximum amount of memory available for running PHP scripts

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Running server side scripts using PHP as an example (LAMP)"

Terms: Running server side scripts using PHP as an example (LAMP)