#49965 [Fbk]: Setting MYSQLI_OPT_CONNECT_TIMEOUT does not seem to have an effect on timeout

2009-10-28 Thread uw
 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:

Ah, looks I'm wrong on the loop. PHP should iterate over all possible
hosts and only decrement remaining time if there are multiple hosts... 


Anyway, fsockopen() would be interesting.


Previous Comments:


[2009-10-28 16:54:33] u...@php.net

Hi Ed,

as you may know from the Wireshark protocol you provided
(mysql-noserver.pcap - MySQL is offline) there is a TCP SYN-RST,ACK 
ping-pong between the client machine and the server. 

PHP tries to establish a connection and sends SYN. The server's
response is RST (, ACK) indicating that no process on the server is
wating for requests on the requested port (MySQL is offline).

At this point PHP should get ECONNREFUSED from connect() and bubble up
the error. But it seems as if this is not the case. According to the
Wireshark protocol the first SYN-RST,ACK is followed by another
connection attempt after about 0.5s which fails. PHP continues to make
another connection attempt after 1s which fails again.

The ping-pong should start because PHP recognizes after 0.5s
respectively 1s that there is time left for more connection attempts
(you set the connect timeout to 5s). 

I don't know why the protocol shows no more records after 1s.

However, can you try using fsockopen() to connect to the MySQL host if
MySQL is offline? 

Something like this:

sapi/cli/php -r '$start = microtime(true); $errno = 0; $error = ; $fp
= fsockopen(tcp://192.168.201.222, 3306, $errno, $error, 5);
var_dump($fp); var_dump($errno); var_dump($error);
var_dump(microtime(true) - $start); '

Again, I'd be interested in the Wireshark protocol (unless it is
blocking endless). 

Thanks!
Ulf



[2009-10-27 21:19:50] ed at bellcpa dot com

Hi Ulf,

I tried a 5.3.2-dev VC9 x86 thread-safe snapshot (not sure how to
obtain 5.3.1) with same results. Also tried a 5 second
default_socket_timeout with no effect.

Will send the captures to you by email.

Thanks



[2009-10-27 10:06:56] u...@php.net

Regarding wireshark protocol: yes, please do mail them to me or offer
them for download anywhere (make sure they don't show any confidential
data, e.g. server IP, username, password!) 

Thanks!
Ulf



[2009-10-27 10:04:54] u...@php.net

60s - we are back to some config problem. Can you try change the
default_socket_timeout? Can you try a 5.3.1 snapshot?

Thanks!
Ulf





[2009-10-26 21:10:09] ed at bellcpa dot com

After further testing:

The php_errors.log messages previously mentioned are logged exactly 60
sec after a connection attempt is made so some timeout is likely in
effect. Also, the script remains running in a hung state after the
errors are logged.

Post connection timeout is not a concern here, instead the issue is
with the length of the timeout when MySQL server is purposely not
online.

I have Wireshark captures for when the MySQL server is offline and
connection times out as well as when MySQL is online and connection
succeeds right away. Can I email these to you?

I am using mysqli on 5.3.0 with default settings, shouldn't mysqlnd be
used by default?

I will try a snapshot soon once I find the time to test.

Thanks!



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/49965

-- 
Edit this bug report at http://bugs.php.net/?id=49965edit=1



#49965 [Fbk]: Setting MYSQLI_OPT_CONNECT_TIMEOUT does not seem to have an effect on timeout

2009-10-27 Thread uw
 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:

Regarding wireshark protocol: yes, please do mail them to me or offer
them for download anywhere (make sure they don't show any confidential
data, e.g. server IP, username, password!) 

Thanks!
Ulf


Previous Comments:


[2009-10-27 10:04:54] u...@php.net

60s - we are back to some config problem. Can you try change the
default_socket_timeout? Can you try a 5.3.1 snapshot?

Thanks!
Ulf





[2009-10-26 21:10:09] ed at bellcpa dot com

After further testing:

The php_errors.log messages previously mentioned are logged exactly 60
sec after a connection attempt is made so some timeout is likely in
effect. Also, the script remains running in a hung state after the
errors are logged.

Post connection timeout is not a concern here, instead the issue is
with the length of the timeout when MySQL server is purposely not
online.

I have Wireshark captures for when the MySQL server is offline and
connection times out as well as when MySQL is online and connection
succeeds right away. Can I email these to you?

I am using mysqli on 5.3.0 with default settings, shouldn't mysqlnd be
used by default?

I will try a snapshot soon once I find the time to test.

Thanks!



[2009-10-23 19:24:29] u...@php.net

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



[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.



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/49965

-- 
Edit this bug report at http://bugs.php.net/?id=49965edit=1



#49965 [Fbk]: Setting MYSQLI_OPT_CONNECT_TIMEOUT does not seem to have an effect on timeout

2009-10-23 Thread uw
 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=49965edit=1