ID: 49511 Updated by: u...@php.net Reported By: casper at procurios dot nl Status: Assigned Bug Type: MySQL related Operating System: * PHP Version: 5.3, 6 (2009-09-09) Assigned To: mysql New Comment:
On the available options on Windows: ext/mysql, ext/mysqli and PDO_MYSQL can either be compiled against the MySQL Client Library or mysqlnd. That is also true for Windows in general. If not, it is a bug. Windows users do have a choice. Pierre, php.net restricts itself on Windows to mysqlnd for a reason. The reason is that you cannot compile current versions of the MySQL Client Library using Visual Studio 6, just like you cannot compile current versions of the MySQL Server using Visual Studio 6. Visual Studio 6 is old - it is from 1998. As far as I know, Microsoft has stopped to support this compiler. Consequently, MySQL has dropped support for it. To my understanding VC 6 is still of relevance for php.net because other projects have or still do use VC 6. I would not want to use an unsupported compiler for my project but they do although there are superior and free offering from Microsoft. Using their products together with a PHP binary that is not compiled with VC 6 can lead to crashes. Therefore, you are looking to support VC 6, which is not possible when using the MySQL Client Library. If one fails to use a recent version of the MySQL Client Library together with ext/mysql, ext/mysqli or PDO_MYSQL on Windows using a recent Visual Studio it should be reported as a bug. Previous Comments: ------------------------------------------------------------------------ [2009-09-15 14:12:51] paj...@php.net It is not correct to say that mysqlnd on windows differs from libmysql. Libmysql uses native APIs directly no matter the platform while mysqlnd always uses php's stream, on every platform. The different between windows and unix is that windows relies on mysqlnd only (no choice, no compatible library available). ------------------------------------------------------------------------ [2009-09-15 13:34:28] u...@php.net Note: MYSQL_OPT_READ_TIMEOUT != MYSQL_OPT_CONNECT_TIMEOUT . What you are saying is that you query times out. The report is not about a connection timeout. Your timeout happens after the connection has been established and therefore setting MYSQLI_OPT_CONNECT_TIMEOUT won't change anything. In the end ext/mysqli is a wrapper of the MySQL C API and thus we can consult the C API documentation on the difference. The docs at http://dev.mysql.com/doc/refman/5.1/en/mysql-options.html explain: MYSQL_OPT_CONNECT_TIMEOUT (argument type: unsigned int *) Connect timeout in seconds. MYSQL_OPT_READ_TIMEOUT (argument type: unsigned int *) The timeout in seconds for attempts to read from the server. Each attempt uses this timeout value and there are retries if necessary, so the total effective timeout value is three times the option value. You can set the value so that a lost connection can be detected earlier than the TCP/IP Close_Wait_Timeout value of 10 minutes. This option works only for TCP/IP connections and, prior to MySQL 5.1.12, only for Windows. MYSQL_OPT_READ_TIMEOUT has never been supported by ext/mysqli. You can easily check that by "grepping" through the source of ext/mysqli as contained in, for example, PHP 5.2.10. nixn...@ulflinux:~/ftp/php-5.2.10> grep -i -R MYSQL_OPT_READ_TIMEOUT ext/ nixn...@ulflinux:~/ftp/php-5.2.10> grep -i -R MYSQLI_OPT_READ_TIMEOUT ext/ nixn...@ulflinux:~/ftp/php-5.2.10> However, mysqlnd is not the MySQL Client Library, mysqlnd makes use of PHP Streams. Looks like PHP Streams use different default timeouts than the MySQL Client Library on Windows. That is a problem for you as a user, no doubt. Question is how to solve that problem. ------------------------------------------------------------------------ [2009-09-09 19:49:41] j...@php.net See also bug #49436 ------------------------------------------------------------------------ [2009-09-09 12:54:30] casper at procurios dot nl I found a workaround: Apparently mysqlnd does listen to 'default_socket_timeout'. ini_set('default_socket_timeout', 5) sets a 5 second limit I found that ini_set('default_socket_timeout', -1) disables the timeout all together, though that might be undocumented behaviour. $storeTimeout = ini_set('default_socket_timeout', -1); $link = mysqli_init(); mysqli_real_connect($link, 'localhost', 'root', '', 'mysql', null, null, MYSQLI_CLIENT_INTERACTIVE); ini_set('default_socket_timeout', $storeTimeout); mysqli_query($link, 'SELECT SLEEP(62)'); mysqli_close($link); ------------------------------------------------------------------------ [2009-09-09 12:24:02] casper at procurios dot nl Description: ------------ It seems that mysqli using mysqlnd has a set timeout of 60 seconds for a query. If you run a query that takes longer, the 'MySQL server has gone away' error is cast. Furthermore when I try to set MYSQLI_OPT_CONNECT_TIMEOUT, it won't comply. In the reproduce code below, I get the errors only after 60 seconds, where I expected to see them at 5 seconds. Reproduce code: --------------- $link = mysqli_init(); mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 5); mysqli_real_connect($link, 'localhost', 'root', ''); mysqli_query($link, 'SELECT SLEEP(62)'); mysqli_close($link); Actual result: -------------- PHP Warning: mysqli_query(): MySQL server has gone away in /home/casper/mysqltest.php on line 7 Warning: mysqli_query(): MySQL server has gone away in /home/casper/mysqltest.php on line 7 PHP Warning: mysqli_query(): Error reading result set's header in /home/casper/mysqltest.php on line 7 Warning: mysqli_query(): Error reading result set's header in /home/casper/mysqltest.php on line 7 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49511&edit=1