Page 1 of 1

How to get Object size

Posted: Fri Apr 25, 2008 11:37 am
by victorsk
Hello,

I have a question. I have an object that I obtain from making a SOAP request. This object contains lots of multidimensional arrays. What I need to know is the memory size of this object. I tried to write it into a file, but all I got was Array Array, but these arrays contain huge amounts of text. So I tried the following:

Code: Select all

 
$fp = fopen('file.txt', 'w');
fwrite($fp, print_r($my_object));
 
But I got strange output "11". I need to get the memory size of this object. So I try to place its contents into a file. Is there a way to:

1) Either write object's contents into a file similar to what I try to do.
2) Is there a generic PHP function that returns the size of an object given an object as parameter?

Thank you so much,
Victor.

Re: How to get Object size

Posted: Fri Apr 25, 2008 3:19 pm
by Zoxive
print_r - Check out the documentation : p

Code: Select all

fwrite($fp, print_r($my_object,true));// Need to tell it to return, and not print
Other then that, I think th easyiest way is to run memory_get_usage, right before you get the object. Then again after. It wont be completely accurate, because it is measuring everything going on.

Re: How to get Object size

Posted: Fri Apr 25, 2008 4:50 pm
by victorsk
thank you :D