PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » MDB2 » Bug #8926

the connection is destructured when a child fork exits

Details

Submitted2006-10-10 10:27 UTC
Fromalex at alatest dot com
Assignedlsmith
StatusWont fix
PackageMDB2
PHP Version5.1.2
OSLinux (maybe all)
Roadmaps(Not assigned)

Comments

[2006-10-10 10:27 UTC] alex at alatest dot com

Description:
------------
When forking to do some work in the background the database connection gets shut down when the child exits.

Test script:
---------------
$dsn = array('phptype' => 'mysql', 'username' => 'root', 'password' => '*****', 'hostspec' => '192.168.1.3', 'database' => 'alacalc');
$dbh = MDB2::connect($dsn, $options);

$res = $dbh->query("SELECT SourceID,WWW,Name,SourcePic FROM source");
$all = $res->fetchAll(MDB2_FETCHMODE_ASSOC);
for($i = 0; $i < count($all); $i++) {
if($all[$i]["foo"] == "bar") {
$res = $dbh->exec("UPDATE source SET LogoURL='" . $source_newimg . "' WHERE SourceID=" . $row["SourceID"]);

$pid = pcntl_fork();//fork the process here
if(!$pid) { //child
//do something that takes long time
exit(0); //child exits here now $dbh is dead
}
}
}

Expected result:
----------------
a lot of updates to the database

Actual result:
--------------
an error the second time the sql in the loop is run

[2006-10-11 13:30 UTC] alex at alatest dot com

I haven't tried it with the native code, but it sounds likly that it could be the cause of it.

I thought that maybe you did some cleanup when your object got destructed, i was very frustrated when i discovered the reason for my bug after hunting it for an hour.

maybe i should push this upstream to the php team.

[2006-10-29 00:11 UTC] neufeind at php dot net

Somehow related:
http://bugs.php.net/bug.php?id=31538

They just said that you need a separate connection for each child, no other solution. That was back in 2005 ...