[php-src] Issue #20084: Closing PDO descriptors for child processes
| From: | jdwx | Date: | Mon, 06 Oct 2025 20:03:00 +0000 |
| Subject: | [php-src] Issue #20084: Closing PDO descriptors for child processes | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-251004@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/20084
Author: jdwx
### Description
At least on Unix systems, whenever PHP creates a child process, whether through conventional means
like shell_exec(), passthru(), or proc_open(), or through stuff like pcntl_fork(), the child process
inherits all of the open file descriptors, including any open authenticated PDO database
connections.
This is generally not desirable. Even in contexts where it's not a security concern, two
processes should not share one connection to a database because the first one to use it will mess it
up for the other one.
In other languages, this is avoided by calling something like:
```c
fcntl( fd, F_SETFD, F_CLOEXEC );
```
on the database's file handle. But PHP doesn't provide this functionality (that I'm
aware of) without exotic extensions and even if it did, there's no way (that I'm aware of)
to get at the system file descriptor corresponding to a PDO connection.
Would it be possible/reasonable to add something to PDO::setAttribute() that would, when invoked,
set that flag on the underlying descriptor where it is applicable?