ID:               49965
 Updated by:       u...@php.net
 Reported By:      ed at bellcpa dot com
 Status:           Feedback
 Bug Type:         MySQLi related
 Operating System: Windows Server 2008
 PHP Version:      5.3.0
 New Comment:

PS: don't rely on connect timeout of libmysql - it does not work in
every case. Check bugs.mysql.com.


Previous Comments:
------------------------------------------------------------------------

[2009-10-23 19:22:04] u...@php.net

Can you give more details? I'm unable to reproduce the issue with
5.3.2-dev (= should become 5.3.1). Is it possible for you to try a
snapshot? Can you provide me with a Wireshark (network sniffer)
protocol?

The connect timeout itself should work. If not, it should be a streams
or Windows matter. First question is what exactly "connect timeout"
means. A wireshark protocol should be able to tell. In 5.3.0 you may get
a successful connect within the time limit you set but then, when
reading data, experience default_socket_timeout.

Thanks!

------------------------------------------------------------------------

[2009-10-23 18:37:11] ed at bellcpa dot com

Worked around the problem for now by testing the connection with
fsockopen prior to real_connect.

------------------------------------------------------------------------

[2009-10-23 17:13:43] ed at bellcpa dot com

Oh but I did search and have seen #49511 propr to submitting....


#49511 mainly focuses on a query timeout and not a connection timeout,
which is my issue. MYSQL_OPT_CONNECT_TIMEOUT mentioned is unaddressed.

Also tried ini_set('default_socket_timeout', 5) as suggested in that
submission with no effect.

------------------------------------------------------------------------

[2009-10-23 10:22:33] j...@php.net

See bug #49511, and thank you for not searching before submitting..

------------------------------------------------------------------------

[2009-10-23 08:10:25] ed at bellcpa dot com

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

Reply via email to