Bug #81155 [Opn]: Mysql close is NOT synchronous
Edit report at https://bugs.php.net/bug.php?id=81155&edit=1
ID: 81155
Updated by: dharman@php.net
Reported by: video dot ice dot power at seznam dot cz
Summary: Mysql close is NOT synchronous
Status: Open
Type: Bug
Package: PDO MySQL
Operating System: any
PHP Version: 8.0.7
Block user comment: N
Private report: N
New Comment:
This could also be a problem with MySQL server. FWIW I cannot reproduce it on my machine.
Previous Comments:
------------------------------------------------------------------------
[2021-06-17 14:35:31] video dot ice dot power at seznam dot cz
Description:
------------
Mysql close is NOT synchronous - it does NOT wait until the connection is closed/released by the
database server which causes more simultaneous connections than needed from a script than
connect/disconnect from the same database often.
An example of such usecase is unit testing.
I have tested also PostgreSQL. This PDO driver handles close synchronously/ok (SQL to limit
connections: ALTER ROLE user CONNECTION LIMIT 1).
MySQL driver needs to be fixed as even server limit of 2 is not enough, currently limit of like 5 is
needed even if there is no more than 1 simultaneous client connection.
Test script:
---------------
# 1. limit connection limit to 1
php -r '(new PDO("mysql:host=mysql", "user",
"pass"))->exec("ALTER USER
'"'"'user'"'"'@'"'"'%'"'"'
WITH MAX_USER_CONNECTIONS 1");'
# 2. connect/disconnect often
for ($i = 0; $i < 10000; $i++) {
(new PDO("mysql:host=mysql", "user",
"pass"))->exec("SELECT 1");
}
Expected result:
----------------
no error
Actual result:
--------------
connection limit is exhausted about every 1000th connection
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81155&edit=1
Thread (2 messages)