note 38992 added to function.memory-get-usage
| From: | MagicalTuxatFF dot ST at rn2 dot php dot net | Date: | Wed, 14 Jan 2004 10:09:15 +0000 |
| Subject: | note 38992 added to function.memory-get-usage | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63498@lists.php.net to get a copy of this message | ||
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)
----
Manual Page -- http://www.php.net/manual/en/function.memory-get-usage.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38992
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38992&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38992&report=yes
Search -- http://master.php.net/manage/user-notes.php