From: Operating system: vistax64 PHP version: 5.3.2 Package: MySQLi related Bug Type: Bug Bug description:Mysqli - zombie links
Description: ------------ Mysqli generated links appear to be persistent regardless of settings as long as the PHP process (or Apache server process if PHP is loaded as a module as in my case) is running. Any new connections just add to the total link count, and neither closing or unsetting the link nor garbage collection has any effect on removing them. Restarting mysqld has no effect. I'm using Vista x64, Apache 2.2, PHP5.3.2 as a module (thread-safe download), and Mysql 5.1.45. The below code produces no Mysql error, but after the second page reload, PHP generates a 'Too many open links (1)' error from that point on until the PHP server process is restarted. Mysql shows no connection attempts on its end. No further db links can be established because of mysqli.max_links being reached. The only way to solve this that I've found so far is to set mysqli.max_links=-1 and just ignore the ever-growing number of zombie links. Either that or restart the Apache server every few seconds. Also of note, no matter how high max_links is set and the script is ran, get_connection_stats() will only show 1 active_connections, 0 active_persistent_connections, 0 connection_reused, 0 reconnect, 0 *_close. Also, when using mysqli::real_connect method after mysqli_init(), it establishes 1 active_persistent_connections according to get_connection_stats() even though I have mysqli.allow_persistent=Off, where as mysqli::__construct does not. Test script: --------------- php.ini... mysqli.max_links = 1 mysqli.allow_persistent = Off mysqli.max_persistent = 0 mysqli.reconnect = Off my.ini... max_connections=1 max_user_connections=1 connect_timeout=10 // just hit browser refresh once or twice <?php $mysqli = mysqli_init(); $mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5); $mysqli->real_connect($m_host, $m_user, $m_pass, $m_db); echo $mysqli->error."<br>"; var_dump($mysqli->get_connection_stats()); mysqli_close($mysqli); die("finished"); ?> Expected result: ---------------- The above code should never generate a PHP error. Link in PHP memory should actually be deleted either on close() or on script end. If this behavior is intended for another purpose, in order to free up memory and available connection/link slots in PHP, can a function or setting be added or tweaked to actually delete the link from memory either on demand or after some user specified time limit, or automatically on script end? Or is there another method of handling this already? Should there be a mysql(i).connect_timeout setting in php.ini? Is mysqli::real_connect disobeying mysqli.allow_persistent=Off? Actual result: -------------- [19-Apr-2010 12:56:58] PHP Warning: mysqli::mysqli(): Too many open links (1) in D:\Server\Scripts\mysql_benchmarks.php on line 15 [19-Apr-2010 12:56:58] PHP Warning: main(): Couldn't fetch mysqli in D:\Server\Scripts\mysql_benchmarks.php on line 16 [19-Apr-2010 12:56:58] PHP Warning: mysqli::get_connection_stats(): Couldn't fetch mysqli in D:\Server\Scripts\mysql_benchmarks.php on line 17 -- Edit bug report at http://bugs.php.net/bug.php?id=51605&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51605&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51605&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51605&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51605&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51605&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51605&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51605&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51605&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51605&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51605&r=support Expected behavior: http://bugs.php.net/fix.php?id=51605&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51605&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51605&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51605&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51605&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51605&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51605&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51605&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51605&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51605&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51605&r=mysqlcfg