note 38992 deleted from function.memory-get-usage by nlopess
| From: | nlopess@php.net | Date: | Wed, 14 Jan 2004 19:11:40 +0000 |
| Subject: | note 38992 deleted from function.memory-get-usage by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-63555@lists.php.net to get a copy of this message | ||
Note Submitter: MagicalTux at FF.ST
----
I had to write an application using lots of memory (cache a table - 1300000 entries - in
"recursive" arrays and search it when requested from someone - via UDP socket)
I used this function to display in the console the amount of used memory (while loading table, and
after).
Loading table : 1307672/1307672 (100%) - Memory: 524.71MB
Loaded 1307672 records - using 524.71MBbytes in memory (420.75B per record).
(Each record contain : 2x int and 1x 2bytes string)
On this server, I only have 390MB of RAM. That mean that this function will return the amount of
memory used in RAM and in SWAP. The other comment about using ps will only return the amount of RAM
used and not the amount of memory used.
Function used to get a nice display of the memory (can be used for anything : file size, etc...) :
<?php
function formatval($val) {
$t=array('B','kB','MB','GB');
$i=0;
while($val>1024) {
$i++;
if (!isset($t[$i])) { $i++; break; }
$val=$val/1024;
}
$res=round($val,2).$t[$i];
return $res;
}
?>
(note that my search system was a success. Searching one entry took 3 seconds with mysql - where
clause - and 0.1msec with my little php thing)