How to get the amount of memory that allocated with currently running PHP script

3 Answers

0 votes
echo memory_get_usage() . " bytes";

/*
run: 

127800 bytes 

*/

 



answered Jul 5, 2016 by avibootz
0 votes
echo memory_get_usage() . " bytes <br />";

$s = str_repeat("PHP", 1000);

echo memory_get_usage() . " bytes <br />";

unset($s);

echo memory_get_usage() . " bytes <br />";

/*
run: 

128768 bytes 
131904 bytes 
128808 bytes 

*/

 



answered Jul 5, 2016 by avibootz
0 votes
$total_memory = memory_get_usage();

$memory_size = array('Bytes','KB','MB','GB','TB','PB');

echo round($total_memory/pow(1024,($i = floor(log($total_memory,1024)))),2).' '.$memory_size[$i];


  
/*
run:
       
376.77 KB
      
*/

 



answered Mar 21, 2019 by avibootz

Related questions

1 answer 207 views
1 answer 270 views
1 answer 278 views
1 answer 272 views
1 answer 144 views
1 answer 223 views
...