|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48447 After FORK Interbase doesn't work
Submitted: 2009-06-01 17:02 UTC Modified: 2021-03-31 11:35 UTC
Avg. Score:4.2 ± 1.0
Reproduced:5 of 5 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (20.0%)
From: jjoss at mail dot ru Assigned:
Status: Suspended Package: InterBase related
PHP Version: 5.2.9 OS: Ubuntu Linux 2.6.18
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jjoss at mail dot ru
New email:
PHP Version: OS:


 [2009-06-01 17:02 UTC] jjoss at mail dot ru
After using the pcntl_fork() function both parent and child are not able to connect to the database.

Reproduce code:
  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);

    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);

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

Expected result:
$ php fork_interbase.php
grandpa: 27850
    [0] => 1
child: 27852
    [0] => 1
parent: 27850
    [0] => 1

Actual result:
$ php fork_interbase.php
grandpa: 27850
    [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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-06-03 09:37 UTC]
-Assigned To: +Assigned To: mariuz
 [2012-01-05 09:05 UTC] 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.
 [2012-11-21 08:41 UTC] 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.
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:
$db_handle = null;
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.
 [2017-10-24 06:46 UTC]
-Status: Assigned +Status: Open -Assigned To: mariuz +Assigned To:
 [2019-03-23 16:40 UTC] lester at lsces dot co dot uk
This is another facet of the problem of trying to use the same database multiple times. If I close the connection before forking, then a new resource is created in the child or the parent and works. Not sure just what is intended here as I can't see how you would carry the open connection to a different thread?
 [2021-03-31 11:35 UTC]
-Status: Open +Status: Suspended
 [2021-03-31 11:35 UTC]
The interbase extension is moved to PECL[1] as of PHP 7.4.0, and
is looking for a new maintainer.  Until a new maintainer is found,
I suspend this ticket.

Consider to use the bundled PDO_Firebird extension, or the
php-firebird package[2] instead.

[1] <>
[2] <>
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Feb 03 05:03:49 2023 UTC