Page 1 of 1

Viewing objects in memory

Posted: Mon Apr 18, 2005 5:27 pm
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

Posted: Tue Apr 19, 2005 4:43 am
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

Posted: Tue Apr 19, 2005 5:26 am
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

Posted: Tue Apr 19, 2005 10:13 am
by feyd
I don't think that's fully possible outside of maybe Zend..