获取 PHP 中对象在内存中的大小?
可以在为已创建类分配内存之前和之后使用 memory_get_usage() 函数。
class MyBigClass { var $allocatedSize; var $allMyOtherStuff; } function AllocateMyBigClass() { $before = memory_get_usage(); $ret = new MyBigClass; $after = memory_get_usage(); $ret->allocatedSize = ($after - $before); return $ret; }
输出将是对象在环境设置方面的内存。
广告