Pear DB and memory usage, strange...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vincent

    Pear DB and memory usage, strange...

    Hi

    I have a problem with pear DB

    my code :

    for ($i=0;$i<100000 ;$i)
    {
    $sql = "select id from table where id=x";

    $db->query($sql);
    }

    if i run this code memory usage grow up, during for loop

    but if i use mysql_query($sq l) instead of $db->query($sql), memory
    usage stay the same during all for loop

    Have you an idea to solve my problem ?

    vincent
  • Nikolai Chuvakhin

    #2
    Re: Pear DB and memory usage, strange...

    saucisson@gmail .com (Vincent) wrote in message
    news:<77da1f3d. 0410150323.16cc 2d86@posting.go ogle.com>...[color=blue]
    >
    > I have a problem with pear DB
    >
    > my code :
    >
    > for ($i=0;$i<100000 ;$i) {
    > $sql = "select id from table where id=x";
    > $db->query($sql);
    > }
    >
    > if i run this code memory usage grow up, during for loop
    >
    > but if i use mysql_query($sq l) instead of $db->query($sql), memory
    > usage stay the same during all for loop[/color]

    This is a rather well-known deficiency in memory management in PHP 4.
    Memory allocated to objects is not released until the end of script's
    execution.
    [color=blue]
    > Have you an idea to solve my problem ?[/color]

    Don't use OOP in general and database abstraction layers in particular.
    Another option is to switch to PHP 5, where this problem has purportedly
    been solved.

    Cheers,
    NC

    Comment

    • Zurab Davitiani

      #3
      Re: Pear DB and memory usage, strange...

      Nikolai Chuvakhin wrote:
      [color=blue][color=green]
      >> for ($i=0;$i<100000 ;$i) {
      >> $sql = "select id from table where id=x";
      >> $db->query($sql);
      >> }
      >>
      >> if i run this code memory usage grow up, during for loop
      >>
      >> but if i use mysql_query($sq l) instead of $db->query($sql), memory
      >> usage stay the same during all for loop[/color]
      >
      > This is a rather well-known deficiency in memory management in PHP 4.
      > Memory allocated to objects is not released until the end of script's
      > execution.[/color]

      To be more accurate, PHP4 releases memory taken by objects created from
      simple user classes before the script ends - i.e. when variable is no
      longer used or it is being assigned a new value. But it doesn't work the
      same way when you have an object from a more complex class structure.
      Exactly what causes it - I don't know.
      [color=blue][color=green]
      >> Have you an idea to solve my problem ?[/color]
      >
      > Don't use OOP in general and database abstraction layers in particular.
      > Another option is to switch to PHP 5, where this problem has purportedly
      > been solved.[/color]

      Yes, at least with what I have tested, memory usage still starts to grow,
      but levels out at some point. In my testing, it's definitely not nearly as
      efficient as using variables and functions.

      Even if OP were to switch to and run the script in PHP5, it would be a good
      idea to first try the script both ways (with and without objects in the for
      loop) and track the memory usage during that for loop to help him decide if
      using objects is right for him.

      Comment

      • Markus Elfring

        #4
        Re: Pear DB and memory usage, strange...

        > if i run this code memory usage grow up, during for loop[color=blue]
        >
        > but if i use mysql_query($sq l) instead of $db->query($sql), memory
        > usage stay the same during all for loop
        >
        > Have you an idea to solve my problem ?[/color]

        How are the memory requirements on your system with the following alternative?

        // http://pear.php.net/package/DB/docs/...#methodprepare
        $statement = $db->prepare('selec t x from table where id = ?');

        for ($i = 0; $i < 100000; ++$i)
        {
        $result = $db->execute($state ment, $i);
        }

        $db->freePrepared($ statement);


        Regards,
        Markus

        Comment

        Working...