Skip to content

Connection problems with postgres pdo using php 8.3.10 and 8.2.22 #15637

@mathieu-pillar

Description

@mathieu-pillar

Description

The following code:

// Database connection details
$host = '<ip of common database>';
$dbname = 'postgres'; 
$user = 'postgres';
$pass = '<password>';

try {
    // Create a new PDO instance
    $dsn = "pgsql:host=$host;dbname=$dbname";
    $pdo = new PDO($dsn, $user, $pass);

    // Set error mode to exception
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // SQL query
    $sql = "SELECT * FROM topics LIMIT 20";

    // Execute the query
    $stmt = $pdo->query($sql);

    // Fetch all results
    $topics = $stmt->fetchAll(PDO::FETCH_ASSOC);

    // Display the results
    foreach ($topics as $topic) {
        echo "ID: " . $topic['id'] . " - Title: " . $topic['display_name'] . "\n";
    }

} catch (PDOException $e) {
    // Handle connection error
    echo "Connection failed: " . $e->getMessage();
    
    throw $e;
}

// Close the connection
$pdo = null;

Resulted in this output:

Connection failed: SQLSTATE[08006] [7] could not send SSL negotiation packet: Resource temporarily unavailablePHP Fatal error:  Uncaught PDOException: SQLSTATE[08006] [7] could not send SSL negotiation packet: Resource temporarily unavailable in /home/forge/test.php:12
Stack trace:
#0 /home/forge/test.php(12): PDO->__construct()
#1 {main}
  thrown in /home/forge/test.php on line 12

Fatal error: Uncaught PDOException: SQLSTATE[08006] [7] could not send SSL negotiation packet: Resource temporarily unavailable in /home/forge/test.php:12
Stack trace:
#0 /home/forge/test.php(12): PDO->__construct()
#1 {main}
  thrown in /home/forge/test.php on line 12

But I expected this output instead:

My data from the table to be printed to the console

More context and tests

I have been working on setting up a production environment at work. We already had a staging server in place. So I am mirroring my setup that I have in staging for my production. I am now facing a wall trying to connect to a remote database other eth1 (private ip) between two Digital Ocean droplets. It all seems to point to a php source error.

Here is a network diagram of my setup.

image

Flow C and D work fine regardless of php version installed. They use localhost as host. Using php pdo.

Flow A and B use eth1 (private ip) on digital ocean to communicate between droplets inside the same VPC using php pdo

Flow A works only using php 8.3.2 (which was installed a few months ago). I installed 8.2 today which resolved to 8.2.22 and I get the exception mentioned above.

Flow B does not work with either 8.3.10 or 8.2.22

Also, I can connect to the common database using psql from both staging and production droplets without issue.

PHP Version

8.3.10, 8.2.22

Operating System

Ubuntu 22.04, Ubuntu 24.04

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions