Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

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 195 views
1 answer 258 views
1 answer 267 views
1 answer 261 views
1 answer 136 views
1 answer 206 views
...