note 55921 added to function.memory-get-usage
| From: | grey-greywyvern-com at osu1 dot php dot net | Date: | Wed, 17 Aug 2005 19:37:37 +0000 |
| Subject: | note 55921 added to function.memory-get-usage | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93806@lists.php.net to get a copy of this message | ||
If nothing else in the user notes below works for you, you can get a very (VERY) rough estimate of
PHP memory usage by outputting the $GLOBALS array, stripping it of indentation whitespace, and
counting the characters in the resulting string. This method has a very high overhead (to be
expected), but works on all operating systems, regardless of whether or not they have the
--enable-memory-limit config option set. I find that the syntax overhead of the print_r() statement
roughly accounts for the PHP runtime base memory usage.
The code below is set up to work on all arrays, not just the $GLOBALS array. Keep in mind that
outside data referenced by resource IDs, such as database results and open file data, is not
included in this total.
<?php
function array_size($arr) {
ob_start();
print_r($arr);
$mem = ob_get_contents();
ob_end_clean();
$mem = preg_replace("/\n +/", "", $mem);
$mem = strlen($mem);
return $mem;
}
$memEstimate = array_size($GLOBALS);
?>
Use only if being off to either side by at least 20% is acceptible for your purposes.
----
Manual Page -- http://www.php.net/manual/en/function.memory-get-usage.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55921
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55921&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55921&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55921&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55921&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55921&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55921&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55921&report=yes
Search -- http://master.php.net/manage/user-notes.php