|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-09-09 12:24 UTC] 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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 20:00:01 2025 UTC |
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);