Still need help with some kind of memory leak in my php database program. General hints for php would help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
Something in my program is eating up memory. I am running php 5 and hooking into postgres8.3, but I don't think it is a database program. The command in question works fine in psql, the problem comes in loading a php variable. And in the past, unsetting the variable has helped.

  The program itself is perhaps 1000 lines long, so I won't post it.
  I tried to isolate the problem with this code:




require_once('/hdir/0/maryfran/unproto/memdev/config_file.php'); // connects to database require_once('/hdir/0/maryfran/unproto/memdev/DMEM_stuff.php'); // has constants for app

function do_select_many($pg,
                       $select_cmd){
global $DMEM_ERROR, $DMEM_DEBUG;
    @pg_connection_status($pg) === PGSQL_CONNECTION_OK
      or die("Database connection bad.\n");
    $sql_result = @pg_query($pg, $select_cmd);
    if (pg_result_status($sql_result) != PGSQL_TUPLES_OK){
        if ($DMEM_DEBUG){
           echo pg_last_error($pg);
           echo "\n<br>\n";
           echo $select_cmd;
           echo "\n<br>\n";
       }
       return array($DMEM_ERROR);
    }
$values_hashed_by_column = pg_fetch_all($sql_result); ///WHERE THE APPLICATION BOMBS
    pg_free_result($sql_result);
    return $values_hashed_by_column;
}

function fu_bar($pg, $sql_cmd){
       $foo = do_select_many($pg,
                             $sql_cmd);
       return($foo);
}

$BIG_SELECT_cmd = " SELECT value,
       x.d8_dv_id,
       x.dm2_dv_id,
       x.dm1_dv_id,
       x.d5_dv_id,
       x.d7_dv_id,
       x.xp_data_batch_id,
       x.xp_sub_batch_id

FROM display.tmp_xprod_table x LEFT JOIN display.tmp_data_values v
ON  x.d8_dv_id = v.d8_dv_id
AND x.dm2_dv_id = v.dm2_dv_id
AND x.dm1_dv_id = v.dm1_dv_id
AND x.d5_dv_id = v.d5_dv_id
AND x.d7_dv_id = v.d7_dv_id
AND x.xp_data_batch_id = v.data_batch_id
AND x.xp_sub_batch_id = v.sub_batch_id
ORDER BY x.d8_value_rank,
         x.dm2_value_rank,
         x.dm1_value_rank,
         x.d5_value_rank,
         x.d7_value_rank,
         x.xp_dmem_status,
         x.xp_created_date ";


$many_selected = fu_bar($pg,
                        $BIG_SELECT_cmd);

// IF I RUN THIS THROUGH A LOOP:
// for($j=0;$j<20, $j++){ $many_selected[$jj] = fu_bar($pg, $BIG_SELECT_cmd)} THE TEST PROGRAM CRASHES so I think I have
more copies of the result of this query than I need.



?>
<p> <?php echo_submit('push_my_button', "Push"); ?></p> //Code which prints a submit button (<input type="submit">)


BIG_SELECT is the only command which pulls a significant amount of data (40K to 2M) into the database. In the real application, executing the function which runs this command results in an memory fault at the point in do_select_many that I have indicated. However, this piece of test code runs just fine! And the BIG_SELECT_cmd works just fine when cut and pasted directly into psql. Sometimes, even the real application will work just fine. I am stymied. I can neither isolate the problem in a piece of test code, nor can I reliably fix the problem when it occurs. Any help on debuggers which will find memory leaks in php code, (Yeah. PHP 5.2 has some!) or tricks of the trade in finding them, or tips on where to look would be greatly appreciated. At this point, I really do not know when and where php frees memory. Let me be a little more specific:

1. Does passing a large array as a reference into or out of a function save space?

2. Suppose I hit a submit button. Are all the variables on the page still taking up space?

3. Any known bugs with pg_fetch_all running on 8.3? How do I find them?

4. Suppose I follow a link. Do my variables on the old page still take up space?

        5.  Should I be handling my arrays one chunk at a time?

6. When I exit a php function, isn't all the space used by function variables freed?

7. Why would it sometimes work to clear the cache? This problem seems to me to be an intermittent one.

        8.  Most important,  what good programming practices should I be
following to keep this from happening?


Mary Anderson



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux