note 102079 deleted from function.memory-get-usage by danbrown

From: Date: Wed, 26 Jan 2011 14:45:50 +0000
Subject: note 102079 deleted from function.memory-get-usage by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176345@lists.php.net to get a copy of this message
Note Submitter: akniep at linklift dot net ---- 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.

« previous php.notes (#176345) next »