ID: 49965 Updated by: u...@php.net Reported By: ed at bellcpa dot com Status: Open Bug Type: MySQLi related -Operating System: Windows Server 2008 +Operating System: any -PHP Version: 5.3.0 +PHP Version: 5.*, 6.* -Assigned To: +Assigned To: mysql New Comment:
Hi Ed, thanks for the additional information given in a private mail. Yes, it matters what type the option value has that you pass to mysqli_options(). It matters ever since 5.0. It is irrelevant if you use mysqlnd or libmysql. mysqli_options(mysqli $link, int $option, mixed $value) inspects the type of the $value parameter. If you pass a string value, as stated in your private mail, ext/mysqli forwards a string to mysqlnd resp. libmysql. Both mysqlnd and libmysql expect that the data they get is of the appropriate type for $option allowing them to use a simple cast to interpret the data. String is not the appropriate type for MYSQLI_OPT_CONNECT_TIMEOUT - the cast inside mysqlnd/libmysql causes a bogus value to be used... This will not work: $timeout = "5" mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, $timeout); mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, "5"); You must use the following: $timeout = 5; mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, $timeout); mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 5); Previous Comments: ------------------------------------------------------------------------ [2009-10-28 17:52:26] u...@php.net Interesting. I assume it does not matter if you use 5.3.0 or 5.3.2-dev? Thanks so far! Ulf ------------------------------------------------------------------------ [2009-10-28 17:40:27] ed at bellcpa dot com Ulf, Here is the fsockopen() result, looks like timeout works as expected: C:\temp2>php testme.php PHP Warning: fsockopen(): unable to connect to tcp://192.168.201.222:3306 (A co nnection attempt failed because the connected party did not properly respond aft er a period of time, or established connection failed because connected host has failed to respond. ) in C:\temp2\testme.php on line 6 PHP Stack trace: PHP 1. {main}() C:\temp2\testme.php:0 PHP 2. fsockopen() C:\temp2\testme.php:6 Warning: fsockopen(): unable to connect to tcp://192.168.201.222:3306 (A connect ion attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has fail ed to respond. ) in C:\temp2\testme.php on line 6 Call Stack: 0.0312 324832 1. {main}() C:\temp2\testme.php:0 0.0491 325280 2. fsockopen() C:\temp2\testme.php:6 bool(false) int(10060) string(185) "A connection attempt failed because the connected party did not pro perly respond after a period of time, or established connection failed because c onnected host has failed to respond. " float(5.1100761890411) ------------------------------------------------------------------------ [2009-10-28 17:07:43] u...@php.net 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. ------------------------------------------------------------------------ [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 ------------------------------------------------------------------------ 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=49965&edit=1