Asaf Nevo
Asaf Nevo

Reputation: 11678

php memory_get_usage(true)

i'm building a php server, and i'm logging each command the server is doing. inside my log i've a added a column that shows on each log what was the memory in use in this step using the memory_get_usage(true) function.

from some reason it always shows me 256 (i've divided the function in / 1024 to get it in KB), although i'm connection to an sql server, adding new instance of objects, running loops etc..

why is that ?

this is my log code:

     function serverLog($status, $message)
{       
    global $logFile, $currentTime;
    $log =  "\n" . date("d/m/Y", $currentTime) . "|" . date("H:i:s", $currentTime). "|" . $status . "|" . $message .  "|" . (memory_get_usage(true) / 1024);
    $fp = fopen($logFile, "a+") or die ("can't open file");
    fwrite($fp, utf8_encode($log));
    fclose($fp);
}

Upvotes: 0

Views: 348

Answers (2)

bos
bos

Reputation: 6535

memory_get_usage(true) will show the amount of memory allocated by php (the engine), not what's actually used by the script. Your script probably never requires more than 256, that's why you're seeing that number.

Upvotes: 0

Jeroen
Jeroen

Reputation: 13257

memory_get_usage(true) shows the amount of memory allocated by the PHP engine, which only changes if your script requires more memory.

Upvotes: 1

Related Questions