I currently have a PHP CLI script using Zend Framework extensively which seems to be using a ever larger amount of memory as it runs. It loops through a large set of models retrieved from a database in batches of 1000. Calls to memory_get_usage()
show that the memory usage of the script is always increasing.
This is despite making sure that I'm unsetting the model after every iteration and actually using array_shift()
to reduce the size of the array of models on every iteration.
My question is, in PHP is there a way of discovering the size-in-memory of a variable so I can track what's growing?
Answer: Use the PHP strlen() function You can simply use the PHP strlen() function to get the length of a string. The strlen() function return the length of the string on success, and 0 if the string is empty.
php.net: The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). 64-bit platforms usually have a maximum value of about 9E18.
i don't have a solution to check the size of every variable, but if you use doctrine its probably the reason
you need to use
$Elem->free(true);
another thing is to upgrade to 5.3 (if you dont do it yet), the garbage collector of 5.3 is better
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With