有没有办法获取以字节为单位的PHP变量的大小? [英] Is there a way I get the size of a PHP variable in bytes?
问题描述
我目前有一个使用Zend Framework的PHP CLI脚本,该脚本在运行时似乎正在使用越来越多的内存.它遍历了从数据库中以1000个为一批的大量模型循环.对memory_get_usage()
的调用表明该脚本的内存使用率一直在增加.
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.
尽管要确保在每次迭代后都取消设置模型,并实际上使用array_shift()
来减小每次迭代中模型数组的大小.
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.
我的问题是,在PHP中,有一种方法可以发现变量的内存大小,以便我可以跟踪正在增长的变量吗?
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?
推荐答案
i don't have a solution to check the size of every variable, but if you use doctrine its probably the reason
您需要使用
$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
这篇关于有没有办法获取以字节为单位的PHP变量的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!