|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62571 Postgres PDO connections fail after SIGCHLD called
Submitted: 2012-07-15 23:27 UTC Modified: 2013-10-30 23:26 UTC
Avg. Score:4.2 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:3 (75.0%)
From: spiros_ioannou at yahoo dot gr Assigned: willfitch (profile)
Status: Closed Package: PDO related
PHP Version: 5.3.14 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: spiros_ioannou at yahoo dot gr
New email:
PHP Version: OS:


 [2012-07-15 23:27 UTC] spiros_ioannou at yahoo dot gr
When using pcntl_fork to fork children, and *only* the parent uses the Postgres PDO database connection, the connection becomes unusable after the first child exits and the signal handler is called. If SIGCHLD signal handler is omitted PDO works normally for parent. Tested with and without persistent connections.
Possible relevant bugs: 48447, 45797

Actual result:
PHP Warning:  PDOStatement::execute(): SQLSTATE[HY000]: General error: 7 server closed the connection unexpectedly
This probably means the server terminated abnormally


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-16 00:12 UTC] spiros_ioannou at yahoo dot gr
I revoke the statement of SIGCHLD, it happens even without the handler in some situations, the behaviour seems erratic. Perhaps the database connection is shared with the children, and when the child dies the db variable the connection is closed. 

I tried closing the DB connection first thing on the child but with no results, the error still appears when the child dies.
 [2012-07-21 11:46 UTC] spiros_ioannou at yahoo dot gr
When using persistent connections, even if reopening a new connection *after* forking, the connection fails. The only way to have DB connections is to reopen them after forking, with PDO::ATTR_PERSISTENT => false
 [2012-12-18 21:23 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: willfitch
 [2012-12-18 21:23 UTC]
Can you provide a test script for your issue?
 [2013-10-30 23:25 UTC]
-Status: Assigned +Status: No Feedback
 [2013-10-30 23:25 UTC]
Closing as no feedback has been provided since I asked for it in 2012.
 [2013-10-30 23:26 UTC]
-Status: No Feedback +Status: Closed
 [2016-12-10 04:24 UTC] bartek at bugpoint dot pl
I confirm the existence of this error in php 7.

Here is example code:

|| define('APPLICATION_PATH', realpath(__DIR__ . '/application'));
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));
require_once 'Zend/Application.php';
$application = new Zend_Application(
    APPLICATION_PATH . '/configs/application.ini'

$db = new Zend_Db_Adapter_Pdo_Pgsql(array(
    'host' => 'localhost',
    'username' => 'test',
    'password' => 'hasłodlatest',
    'dbname' => 'test'

echo 'start' . "\n";
$select = $db->select()->from('aaa', '*');
echo "\n";

$pid = pcntl_fork();
if ($pid == -1) {
    // pcntl_fork() failed
    echo('could not fork');
} elseif ($pid) {

} elseif ($pid == 0) {
    // you're in the new (child) process
    exec('/usr/bin/php /home/idea/CLI/test2.php &>/home/idea/CLI/test.log &');

echo 'After fork' . "\n";

while (true) {
    $select = $db->select()->from('aaa', '*');

echo 'Forked' . "\n";
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Jan 18 04:11:03 2022 UTC