How to get Object size

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
victorsk
Forum Commoner
Posts: 43
Joined: Thu Apr 19, 2007 6:55 pm

How to get Object size

Post 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.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: How to get Object size

Post 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.
victorsk
Forum Commoner
Posts: 43
Joined: Thu Apr 19, 2007 6:55 pm

Re: How to get Object size

Post by victorsk »

thank you :D
Post Reply