php / php/php-src

Closing PDO descriptors for child processes

Open
#20,084 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Extension: pdo (core) Feature Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

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:

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with PDO::setAttribute() and the Unix process paths named in the issue: shell_exec(), passthru(), proc_open(), and pcntl_fork(). Determine how PDO connections expose or inherit descriptors and define coverage for the requested behavior; done when the supported setting prevents inheritance where applicable.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
backend, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.