Viewing objects in memory

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
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Viewing objects in memory

Post by thomas777neo »

I would like to know if it is possible to see how much memory an object created by php uses e.g.

Code: Select all

$myClass = new myClass;

$myFunction = $myClass-> myFunction($parameters); // returns array of records
$myFunctionRows = $myFunction[0]["numrows"]; // returned in array

for ($i = 0; $myFunctionRows > $i; $i++) // say 20000 records
{
    $myVar = $myFunction[$i]["myVar"];

    $myClass-> updateFunction($myVar); // simple update query
} //for ($i = 0; $myFunctionRows > $i; $i++)


This is merely a sample of what I am doing in my code. The problem is I loop through many records and update various other tables. To such a degree that my apache server runs constantly at 100% cpu usage. And during the update phase I can see that Mysql also uses some CPU, yet eventually the Mysql processing is dormant and the apache server continues @ full processing.

The code seems clean, and the update queries are basic. What could I be doing wrong???

Is it possible at all to see if during the process which object or process is using the most amount of memory e.g. $myClass: 123KB @ 2% CPU usage.

If the the object or process exceeds a certain amount of memory, the process could be halted to identify the culprit.

I know that a person can block off the code and debug it, but is there any such class etc
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

:bump:

Just found this topic and i would also like to know if this could be done, it would be absolutely invaluable in the development stage
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

I'm not sure if this can be of any help, but anyway:
http://php.net/manual/en/function.memory-get-usage.php
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I don't think that's fully possible outside of maybe Zend..
Post Reply