php.net |  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
Votes:4
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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: spiros_ioannou at yahoo dot gr
New email:
PHP Version: OS:

 

 [2012-07-15 23:27 UTC] spiros_ioannou at yahoo dot gr
Description:
------------
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] willfitch@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: willfitch
 [2012-12-18 21:23 UTC] willfitch@php.net
Can you provide a test script for your issue?
 [2013-10-30 23:25 UTC] willfitch@php.net
-Status: Assigned +Status: No Feedback
 [2013-10-30 23:25 UTC] willfitch@php.net
Closing as no feedback has been provided since I asked for it in 2012.
 [2013-10-30 23:26 UTC] willfitch@php.net
-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:

test1.php:
<?php
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(__DIR__ . '/application'));
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));
require_once 'Zend/Application.php';
$application = new Zend_Application(
    APPLICATION_ENV,
    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', '*');
print_r($db->fetchOne($select));
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 &');
    exit;
}

echo 'After fork' . "\n";

while (true) {
    sleep(5);
    $select = $db->select()->from('aaa', '*');
    print_r($db->fetchOne($select));
}

test2.php:
<?php
echo 'Forked' . "\n";
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Dec 04 02:03:36 2021 UTC