note 120310 deleted from pdo.connections by salathe
| From: | salathe@php.net | Date: | Mon, 21 Sep 2020 14:54:55 +0000 |
| Subject: | note 120310 deleted from pdo.connections by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215373@lists.php.net to get a copy of this message | ||
Note Submitter: me+nospam at tati dot pro
----
If you want to keep connection after fork exit, you can kill with SIGKILL forked process.
<?php
$dbh = new PDO('pgsql:host=localhost;dbname=test', $user, $pass);
$pid = pcntl_fork();
if($pid == 0){
// forked process 'll exit immediately
exit;
}
sleep(1);
$statement = $dbh->query('select 1');
var_dump($statement);
?>
Result: false
<?php
$dbh = new PDO('pgsql:host=localhost;dbname=test', $user, $pass);
$pid = pcntl_fork();
if($pid == 0){
// use sigkill to close process
register_shutdown_function(function(){
posix_kill(getmypid(), SIGKILL);
});
// forked process 'll exit immediately
exit;
}
sleep(1);
$statement = $dbh->query('select 1');
var_dump($statement);
?>
Result: object(PDOStatement)#3 (1) {
["queryString"]=>
string(8) "select 1"
}