|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2023-01-14 16:45 UTC] dharman@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 00:00:02 2025 UTC |
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