From: rgagnon24 at gmail dot com Operating system: CentOS 5.9 PHP version: 5.3.23 Package: MySQL related Bug Type: Bug Bug description:mysqlnd persistent connection handling out of control
Description: ------------ When PHP 5.3 is compiled with --enable-mysqlnd=shared --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd In order to use the native driver, persistent connections using PDO don't appear to use any kind of managable or determinate connection pooling. Running the test script below via apache web server, refreshing the page every few seconds (10 or 12 times), will produce at least 10 connections to the database as shown by the mysql "SHOW PROCESSLIST" command... yet the phpinfo() section will indicate a number that is not the same as the actual number of connections. In my test prior to posting, I had 10 actual connections (of which 9 were sleeping, and the 10th one was just used to run the test query) and phpinfo() showed 5 active_persistent_connections, and pconnect_success was 8 (under the mysqlnd stats section). This leads me to believe there may be a memory leak in the area of code where the module is managing the connection pool. If no memory leak, the management of the connections is off somehow as idle connections to a production webserver are ridiculously high. Test script: --------------- <?php $options = array( PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, ); $host_name = 'database_host'; $database_name = 'some_database'; $port = 3306; $username = 'db_user'; $password = 'db_pass'; $dsn = sprintf("mysql:host=%s;dbname=%s;port=%d", $host_name, $database_name, $port); $dbh = new PDO($dsn, $username, $password, $options); $sql = 'SELECT * FROM test WHERE id=1 LIMIT 1'; print "<pre>"; $stmt = $dbh->query($sql, PDO::FETCH_ASSOC); while ($row = $stmt->fetch()) { var_dump($row); } $stmt->closeCursor(); print '</pre>'; Expected result: ---------------- active_persistent_connections and pconnect_success should be accurate to match what you are really doing. Also the command line 'netstat -anp|grep :3306|grep httpd|grep ESTABLISHED" should show a limit at some point on the number of connections that are persistent, or they should get re-used. Actual result: -------------- There are a lot of unaccounted for idle ESTABLISHED in the netstat command, for connections from httpd to mysql when mysqlnd indicates there are not that many. -- Edit bug report at https://bugs.php.net/bug.php?id=64549&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=64549&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=64549&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=64549&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=64549&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=64549&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=64549&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=64549&r=needscript Try newer version: https://bugs.php.net/fix.php?id=64549&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=64549&r=support Expected behavior: https://bugs.php.net/fix.php?id=64549&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=64549&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=64549&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=64549&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64549&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=64549&r=dst IIS Stability: https://bugs.php.net/fix.php?id=64549&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=64549&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=64549&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=64549&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=64549&r=mysqlcfg