如何在PHP中查找对象使用的内存? (大小) [英] How to find memory used by an object in PHP? (sizeof)

查看:330
本文介绍了如何在PHP中查找对象使用的内存? (大小)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在PHP中查找对象使用的内存? (c的sizeof).我要查找的对象是其中包含字符串和整数的字典,因此很难手动计算. php中的字符串还可以根据编码(utf8等)的长度而变化吗?

How to find memory used by an object in PHP? (c's sizeof). The object I want to find out about is a dictionary with strings and ints in it so it makes it hard to calculate it manually. Also string in php can be of varied length depending on encoding (utf8 etc) correct?

推荐答案

您可以使用 memory_get_usage().

在创建对象之前运行一次,然后在创建对象之后再次运行,并计算两个结果之间的差异.

Run it once before creating your object, then again after creating your object, and take the difference between the two results.

这篇关于如何在PHP中查找对象使用的内存? (大小)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆