Search code examples
phppostgresqlnetwork-programmingpdo

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 openning 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.

Solution

  • 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.