NYCPHP Meetup

NYPHP.org

[nycphp-talk] memory_get_usage() on win32

felix zaslavskiy felix at bebinary.com
Thu Apr 1 15:08:11 EST 2004


I did some test on Linux/mysql4.0.18/php4.3.4

I rewrote the program a bit though , see below.
The memory climbed from initial of Virtual 26680 Resident 9460 to Virtual
26796 Resident 9488. So that is 116KB virual mem increas and 28KB resident
memory increase. What interesting it climbs gradually for about first 200
iterations and then stops climbing. Also after DB stuff is done and only
fake work is done then it does not affect the memory size.

I didnt not use memory_get_usage because my php is not compiled for it. I
dont think this is a memroy leak because it seems like normal operation of
php garbage collection. I would expect the internal tables to grow to some
initial size and not be released at all. Just because a reference is unset
does not mean php has to release the actual memory. Maybe someone with
better internal knowledge of php can understand this better.

My modified test program:
 #!/usr/bin/php -q
<?php
include 'DB.php';
$db_object = &DB::connect('mysql://root:secret@localhost/test',TRUE);
$db_object->setFetchMode(DB_FETCHMODE_ASSOC);
   $count = 0;
   $ref= null;
   $row = null;
function fake_work(){
    $t = array();
    for($x=0;$x < 150; $x++){
        $t[] = $x + 4 + time() + count($t) -
strlen(md5(uniqid(rand()).time())) + rand()%20;
    }
    for($x=149; $x >= 0; $x--){
        unset($t[$x]);
    }
    unset($t);
}
while($count <= 500)
{
    usleep(5000);//dont go crazy
    $res=&$db_object->query( "select linkid from test2 where linkid=2" );
    $row=&$res->fetchRow();
    //this is a dumbed down version, but does the memleak
    $res->free();
    unset($row);
    unset($res);
    $count++;
    //lets do some other fake work
    fake_work();

    echo "tick $count \n";
     //echo memory_get_usage()."\n";
}
fake_work();
unset($db_object);
for($x = 0; $x < 100; $x++)
{   usleep(5000); fake_work(); }
//its kind of useless because it does not let php run
echo "end of run sleeping for 5 seconds\n";
sleep(5);
?>

> Someon reported a bug in DB about a memory leak
> (http://pear.php.net/bugs/bug.php?id=1112)
>
> Their example uses memory_get_usage(), which isn't enabled on Win32
> systems (unless, I guess, I compile my own with the --enable-memory-limit
> configuration option).  Any ideas how I can track memory usage some other
> way via PHP?
>
> Know what, it probably doesn't matter.  I've watched the process via the
> Task Manger's process list (Windows 2000 Pro) and the memory usage doesn't
> increase even after several itterations of the loop.  So he may be having
> a problem due to his OS/PHP/MySQL combination.
>
> Anyone feel like testing it on other platforms?
>
> Other thoughts?
>
> Thanks,
>
> --Dan
>
> --
>  T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
>             data intensive web and database programming
>                 http://www.AnalysisAndSolutions.com/
>  4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>


-- 
Felix Zaslavskiy
felix at bebinary.com
(718) 576-1923
http://www.zaslavskiy.net



More information about the talk mailing list