Bug #48447 [Asn->Opn]: After FORK Interbase doesn't work

From: Date: Tue, 24 Oct 2017 06:46:05 +0000
Subject: Bug #48447 [Asn->Opn]: After FORK Interbase doesn't work
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212023@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=48447&edit=1

 ID:                 48447
 Updated by:         kalle@php.net
 Reported by:        jjoss at mail dot ru
 Summary:            After FORK Interbase doesn't work
-Status:             Assigned
+Status:             Open
 Type:               Bug
 Package:            InterBase related
 Operating System:   Ubuntu Linux 2.6.18
 PHP Version:        5.2.9
-Assigned To:        mariuz
+Assigned To:        
 Block user comment: N
 Private report:     N



Previous Comments:
------------------------------------------------------------------------
[2012-11-21 08:41:18] steffen at kernelguy dot dk

I can confirm this problem.
I'm using it the same way in a spawned process and normally it works just fine.
However:
If I restart the firebird process the forked process keeps getting the transaction error message.
I have tried everything I can think of when I get the error:
ibase_close($db_handle);
$db_handle = null;
Sleep(2);
ibase_connect or ibase_pconnect; // Tried both
ibase_trans; // Always fails

So for the last year I have been restarting my process, after a firebird restart.

------------------------------------------------------------------------
[2012-01-05 09:05:31] steffen at kernelguy dot dk

If I only call ibase_connect from the child code it works.

What I'm doing:
From a php script run by apache I exec a spawn.php script which again calls pcntl_fork.
I can access the database before the fork, which is successfull.
Then after the fork I get the error below when I try to start a new transaction, even after creating
a new connection with ibase_connect:

"WARNING ibase_trans(): Unable to complete network request to host "localhost". Error
writing data to the connection."

If I dont access the database before the fork, then the child code works. So that's my
workaround for now.

------------------------------------------------------------------------
[2009-06-01 17:02:33] jjoss at mail dot ru

Description:
------------
After using the pcntl_fork() function both parent and child are not able to connect to the database.

Reproduce code:
---------------
<?php
  function dbGet($name)
  {
    echo $name.": ".getmypid()."\n";

    $dbLogin    = 'user';
    $dbPassword = 'password';
    $dbDB       = 'localhost:database';
    $dbCharset  = 'WIN1251';
    $dbDialect  = 3;
    $dbRole     = '';

    $dbh = ibase_connect($dbDB, $dbLogin, $dbPassword, $dbCharset, 0, $dbDialect, $dbRole);
    if (!$dbh)
    {
      echo $name.": connection error - ".ibase_errmsg()."\n";
      posix_kill(getmypid(), 9);
    }

    $query = "SELECT * FROM SOMETABLE;";
    if (!$dbResult = ibase_query($dbh, $query))
    {
      echo $name.": query error - ".ibase_errmsg()."\n";
      posix_kill(getmypid(), 9);
    }

    $row = ibase_fetch_row($dbResult);
    ibase_free_result($dbResult);
    ibase_commit();

    if (empty($row)) echo $name.": row empty - ".ibase_errmsg()."\n";
    else echo $name.":\n".print_r($row, true);
  }

//  $error_reporting_level = error_reporting(0);
//  error_reporting($error_reporting_level);
  error_reporting(0);
  dbGet('grandpa');

    //    $this->obj->Log->debug('ReportGeneric before fork
('.getmygid().')');
  $pid = pcntl_fork();
  if ($pid == -1) die('fork error');
  if ($pid)
  {
    // PARENT
    dbGet('parent');
    posix_kill(getmypid(), 9);
  }
  else
  {
    // CHILD
    dbGet('child');
    posix_kill(getmypid(), 9);
  }
?>

Expected result:
----------------
$ php fork_interbase.php
grandpa: 27850
grandpa:
Array
(
    [0] => 1
)
child: 27852
child:
Array
(
    [0] => 1
)
parent: 27850
parent:
Array
(
    [0] => 1
)
Killed
$

Actual result:
--------------
$ php fork_interbase.php
grandpa: 27850
grandpa:
Array
(
    [0] => 1
)
child: 27852
parent: 27850
parent: row empty - Unable to complete network request to host "localhost". Error writing
data to the connection. Broken pipe
child: query error - Unable to complete network request to host "localhost". Error reading
data from the connection.
Killed
$



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=48447&edit=1


Thread (6 messages)

« previous php.bugs (#212023) next »