From: ed at bellcpa dot com
Operating system: Windows Server 2008
PHP version: 5.3.0
PHP Bug Type: MySQLi related
Bug description: Setting MYSQLI_OPT_CONNECT_TIMEOUT does not seem to have an
effect on timeout
Description:
------------
I have a script that attempts to contact/query an MySQL server on a LAN.
If the server is available, the script runs successfully. If the MySQL
server is offline, however, the script hangs along with the browser session
indefinately. This is despite MYSQLI_OPT_CONNECT_TIMEOUT being set to 5
seconds.
Specifically, the script below hangs when "$mysqli->real_connect" is
executed
Looking for a way to timeout connection attempt.
Running VC9 x86 Thread Safe 5.3. Default mysqli/mysqlnd php.ini settings.
The code below worked fine in the past in the same scenario on version
5.2.8.
Reproduce code:
---------------
$mysqli = mysqli_init();
if (!$mysqli) exit(1);
if (!$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
exit(1);
}
if (!$mysqli->real_connect('localhost', 'my_user', 'my_password',
'my_db')) {
exit(1);
}
Expected result:
----------------
Quit in around 5 sec with an code 1 if MySQL is offline.
Actual result:
--------------
Script hangs indefinately and so does a browser session through which the
script is invoked. After some time (e.g. 2-5 min) the following is logged
in php_errors.log:
[23-Oct-2009 00:48:26] PHP Warning: mysqli::real_connect(): [2002] A
connection attempt failed because the connected party did not (trying to
connect via tcp://192.168.201.222:3306) in C:\app\php\script.php on line
30
[23-Oct-2009 00:48:26] PHP Warning: mysqli::real_connect(): (HY000/2002):
A connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because
connected host has failed to respond.
--
Edit bug report at http://bugs.php.net/?id=49965&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=49965&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=49965&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=49965&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=49965&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=49965&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=49965&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=49965&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=49965&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=49965&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=49965&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=49965&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=49965&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=49965&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=49965&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49965&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=49965&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=49965&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=49965&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=49965&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=49965&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=49965&r=mysqlcfg