Edit report at http://bugs.php.net/bug.php?id=51605&edit=1

 ID:               51605
 User updated by:  bastard dot internets at gmail dot com
 Reported by:      bastard dot internets at gmail dot com
 Summary:          Mysqli - zombie links
 Status:           Open
 Type:             Bug
 Package:          MySQLi related
 Operating System: vistax64
 PHP Version:      5.3.2

 New Comment:

Correction on what software I'm using.  I'm using these packages...



mysql-noinstall-5.1.45-winx64.zip (via mysql.com)

php-5.3.2-Win32-VC6-x86.zip (via php.net)

httpd-2.2.15-win32-x86-openssl-0.9.8m-r2.msi (via apache.org)


Previous Comments:
------------------------------------------------------------------------
[2010-04-19 21:27:58] bastard dot internets at gmail dot com

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 this bug report at http://bugs.php.net/bug.php?id=51605&edit=1

Reply via email to