PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB » Bug #1112

Memory Leak in Pear DB

Details

Submitted2004-04-01 16:10 UTC
Frombemis at docutronsystems dot com
Assigneddanielc
StatusBogus
PackageDB
PHP Version4.3.4
OSFedora Core 1
Roadmaps(Not assigned)

Comments

[2004-04-01 16:10 UTC] bemis at docutronsystems dot com

Description:
------------
The row->free() function doesn't work when the Results are empty.
I wanted a basic daemon that selected every two seconds, and did an action based upon the select results.
most of the time the select will return nothing.
I am finding that after two days of running this piece of my daemon my computer is hanging.
I can rewrite this in c, but my whole project is in PHP so I wanted to use PHP in case the project ever needs to be passed on.

Reproduce code:
---------------
#!/usr/bin/php -q
<?php
include 'DB.php';
$db_object = DB::connect('mysql://root:root@localhost/client_files', TRUE);
$db_object->setFetchMode(DB_FETCHMODE_ASSOC);
while(true)
{
usleep(500000);//dont go crazy
$res=$db_object->query( "select doc_id from this_should_work where doc_id=2" );
$row=$res->fetchRow();
//this is a dumbed down version, but does the memleak
$res->free();
unset($row);
unset($res);
echo memory_get_usage()."\n";
}
?>

Expected result:
----------------
I expect that the memory doesn't increase:
so I'd like to see the script output
502608
502608
502608
502608
502608
502608
502608
502608
502608
502608
502608
502608
502608

Actual result:
--------------
what I actually see is our script increasing at a rate of about 120 bytes per loop:
502608
502784
502904
503024
503144
503264
503384
503504
503656
503776
503896
504016
504136
504256
504376
504496
504680
504800

[2004-04-01 20:36 UTC] bemis at docutronsystems dot com

new script as you requested
#!/usr/bin/php -q
<?php
include 'DB.php';
$db_object = DB::connect('mysql://root:root@localhost/client_files',
TRUE);
$db_object->setFetchMode(DB_FETCHMODE_ASSOC);
for( $i=0;$i<1000;$i++)
{
$res=$db_object->query( "select doc_id from this_should_work where doc_id=2" );
$row=$res->fetchRow();
//this is a dumbed down version, but does the memleak
$res->free();
unset($row);
unset($res);
if( $i%50==1 )
echo memory_get_usage()."\n";
}
?>

new results of that script
[root@death poll]# ./try.php
503456
509680
515936
522448
528448
534448
538464
541264
544064
546864
549664
554512
557312
560112
562912
565712
568512
571312
574112
576912
-matt

[2004-04-01 20:44 UTC] bemis at docutronsystems dot com

I upgraded with pear upgrade db, and got the following output
[root@death poll]# pear upgrade DB
downloading DB-1.6.1.tgz ...
Starting to download DB-1.6.1.tgz (89,932 bytes)
.....................done: 89,932 bytes
upgrade ok: DB 1.6.1

then I ran it again
[root@death poll]# ./try.php
521288
524488
527688
530888
534088
537288
537480
537480
537480
537480
537480
537480
537480
537480
537480
537480
537480
537480
537480
537480
I use yum upgrade as often as I see available upgrades. I dont think it upgraded pear though.
I am sorry for any problems
-matt

[2004-04-01 20:56 UTC] bemis at docutronsystems dot com

after upgrading it does not seem to be a problem any more.
I cranked the for loop up to 100000 and the memory size stayed the same after the 5th iteration.