Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible bug with PHP PDO and with PostgreSQL

At the startup of the docker application (with laravel php), for 1 request, connection to database is fine. After the first request I start to get this error.

SQLSTATE[08006] [7] could not send SSL negotiation packet: Resource temporarily unavailable (Connection: pgsql, SQL: (select * from ........)

Using:

  • Laravel v10 and above.
  • PHP 8.3 and above
  • Docker with Ubuntu Latest

I tracked down this problem until I found out that PDO is actually not opening a connection to PostgreSQL. I tested it with iptraf and both pg_connect and PDO. When we use PDO, we get the error above and but when I try to use pg_connect, we can connect and even make a query.

So my findings are, when using iptraf

  • Cannot open a connection using PDO
  • IPTraf does not show connection openned with PDO
  • I can open a connection using pg_connect
  • I can open a connection from a database manager application
  • Happening on both development and production environments

[EDIT]

New findings:

  • The whole setup is working on a virtual machine rather then a docker.
like image 715
Harun Barış Bulut Avatar asked Apr 16 '26 07:04

Harun Barış Bulut


2 Answers

Check the php-swoole package version on your failed deployment. If it is 6.0.0 probably you have here the problem.

Edit: We also have this problem, we deployed a container compiled from last week and one with the same code but compiled this week, the difference was that the swoole package had been updated from version 5x to 6.0.0, which is an alpha version. Mysteriously, this version has sneaked into the Ubuntu repository, not being recommended for production and its changelog indicates several changes and incompatibilities with PDO.

From php pecl

  • No longer supports Swoole\Coroutine\PostgreSQL coroutine client.
  • Swoole-v6.0.0-alpha is a test version and cannot be used in any production environment; it is for testing purposes only.

HOW TO SOLVE IT: Remove swoole if you don't need it. If you need it, right now the previous version is not listed on the repo, so you need to get it alternatively.

like image 178
alibeam Avatar answered Apr 18 '26 05:04

alibeam


I'll add my 2 cents here. We were using

  • PHP 8.2.20
  • Swoole extension (v5) enabled
  • DigitalOcean PostgreSQL Database (v16)
  • Image from official (php:8.2-cli-alpine)
  • Using PDO to connect.

We had similar issues with this two types of errors:

  • with SSL disabled:
    SQLSTATE[08006] [7] could not send SSL negotiation packet: Resource temporarily unavailable
  • With SSL enabled:
    PDOException: SQLSTATE[08006] [7] could not send SSL negotiation packet: Resource temporarily unavailable

Removing the extension did the trick for us.

like image 42
Esteban Serfe Avatar answered Apr 18 '26 04:04

Esteban Serfe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!