Closed mathieu-pillar closed 4 weeks ago
Is it possible that your expected result and current result sections are reversed?
Did you try to connect with psql? If that works with the same connection parameters, there might be a bug in PHP; otherwise more likely there's an issue with your setup.
Also, I can connect to the common database using psql from both staging and production droplets without issue.
I think the OP had mentioned he was successful with psql. What could be possible is the DSN part needs more settings.
Is it possible that your expected result and current result sections are reversed?
Yes indeed, I will correct this
Did you try to connect with psql? If that works with the same connection parameters, there might be a bug in PHP; otherwise more likely there's an issue with your setup.
Yes, I can do flows A to D using psql without any problems. Issue only comes up on specific versions of pdo php
Did you try to connect with psql? If that works with the same connection parameters, there might be a bug in PHP; otherwise more likely there's an issue with your setup.
Yes, I can do flows A to D using psql without any problems. Issue only comes up on specific versions of pdo php
I had a couple of questions :
1/ The various php versions used are they official apt packages for 8.3.10/8.2.22 then 8.3.2 ? ppa repositories ? compiled from source ? 2/ Would the connection still fails if you re trying to connect to the db using the pgsql extension (ie pg_connect) ?
Did you try to connect with psql? If that works with the same connection parameters, there might be a bug in PHP; otherwise more likely there's an issue with your setup.
Yes, I can do flows A to D using psql without any problems. Issue only comes up on specific versions of pdo php
I had a couple of questions :
1/ The various php versions used are they official apt packages for 8.3.10/8.2.22 then 8.3.2 ? ppa repositories ? compiled from source ? 2/ Would the connection still fails if you re trying to connect to the db using the pgsql extension (ie pg_connect) ?
forge@servername:/etc/apt$ grep php -R .
./sources.list.d/laravelphp-ubuntu-forge-noble.sources:URIs: https://ppa.launchpadcontent.net/laravelphp/forge/ubuntu/
./sources.list.d/ondrej-ubuntu-php-noble.sources:URIs: https://ppa.launchpadcontent.net/ondrej/php/ubuntu/
Ok, it works with pg_connect
<?php [5/14041]
// Database connection details
$host = '<ip of common database>';
$dbname = 'postgres';
$user = 'postgres';
$pass = '<password>';
$port = '5432'; // e.g., 5432 (default PostgreSQL port)
// Connection string
$conn_string = "host=$host dbname=$dbname user=$user password=$pass port=$port";
// Establish a connection
$conn = pg_connect($conn_string);
if (!$conn) {
// Handle connection error
echo "Connection failed: " . pg_last_error();
exit;
}
// SQL query with schema
$sql = "SELECT * FROM openalex.topics";
// Execute the query
$result = pg_query($conn, $sql);
if (!$result) {
// Handle query error
echo "Query failed: " . pg_last_error();
exit;
}
// Fetch and display the results
while ($row = pg_fetch_assoc($result)) {
echo "ID: " . $row['id'] . " - Title: " . $row['title'] . "<br>";
}
// Free result and close the connection
pg_free_result($result);
pg_close($conn);
?>
I think it might be related to Swoole. I have seen this issue but have not though much about it because when I install php mysql, I never use Swoole. But I just figured out that Laravel Forge installs Swoole by default (which I was not aware of). I will turning it off/uninstalling see if it fixes the problems.
Also check whether the server listens on a non-standard port. And also check whether the PostgreSQL client libraries are the same.
Confirmed! The culprit is swoole.
I ran
sudo phpdismod swoole
Not necessary for my test, but i'm paranoid, so I restarted php-fpm
sudo systemctl restart php8.3-fpm.service
And no more errors.
Should I close issue here and report my problem in the swoole repository?
might depend on the swoole version I believe.
might depend on the swoole version I believe.
Ok, they already got that under their radar. I will close this here.
Thanks so much to everyone that helped me out today. It was really appreciated! @devnexen @cmb69 @jeffdafoe
Have a nice all
Description
The following code:
Resulted in this output:
But I expected this output instead:
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.
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