note 102079 added to function.memory-get-usage
| From: | akniep at linklift dot net | Date: | Wed, 26 Jan 2011 11:51:36 +0000 |
| Subject: | note 102079 added to function.memory-get-usage | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176326@lists.php.net to get a copy of this message | ||
This comment concerns my function memory_get_usage_by_variable().
------------------------------------------------------------------
I use the following function to determine the rough memory-usage of single variables when debugging,
optimizing my code, or searching for memory-leaks.
Maybe, it can be helpful to some of you or you can develop it further for your personal needs.
When using the function for the first time the variable-sizes may differ by 48 bytes, because that
seems to be the amount of memory PHP needs to address a function at runtime.
Note: The function needs PHP v5.1 or higher, since, a try-and-catch-block is used around serializing
arrays of unknown type.
Attention: The function duplicates the delivered variable in order to determine its memory-usage and
it may blow up your memory-limit when working with "huge" variables. To prevent this
behaviour you may write a condition at the beginning of the function using memory_get_usage(false)
and ini_get("memory_limit") in order to check if PHP already used most of its available
memory... I was too lazy to do that, since, for my needs, this function does what it should do: It
helps me identifying where my code (i.e. my variables) uses a lot of / the most memory.
The "bigger" the input-variables, the more "accurate" the output of this
function will be.
----
Server IP: 217.160.235.204
Probable Submitter: 87.153.237.41
----
Manual Page -- http://www.php.net/manual/en/function.memory-get-usage.php
Edit -- https://master.php.net/note/edit/102079
Del: integrated -- https://master.php.net/note/delete/102079/integrated
Del: useless -- https://master.php.net/note/delete/102079/useless
Del: bad code -- https://master.php.net/note/delete/102079/bad+code
Del: spam -- https://master.php.net/note/delete/102079/spam
Del: non-english -- https://master.php.net/note/delete/102079/non-english
Del: in docs -- https://master.php.net/note/delete/102079/in+docs
Del: other reasons-- https://master.php.net/note/delete/102079
Reject -- https://master.php.net/note/reject/102079
Search -- https://master.php.net/manage/user-notes.php