php – MySQL“wait_timeout”没有被长期查询所尊重?
发布时间:2020-12-13 17:11:34 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试测试似乎被忽略的wait_timeout MySQL设置. PHP脚本: ?phpfunction microtime_float(){ list($usec,$sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec);}$sql = mysqli_connect('localhost','root','mysql');$query = "SHOW
我正在尝试测试似乎被忽略的wait_timeout
MySQL设置.
PHP脚本: <?php function microtime_float() { list($usec,$sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } $sql = mysqli_connect('localhost','root','mysql'); $query = "SHOW VARIABLES WHERE Variable_name='wait_timeout';"; $result = $sql->query($query) or die($query.'<br />'.$sql->error); $row = $result->fetch_object(); echo "wait_timeout = " . $row->Value . "<br/>n"; $time_start = microtime_float(); $query = "SELECT SLEEP(2) FROM mysql.user;"; $sql->query($query) or die($query.'<br />'.$sql->error); $time_end = microtime_float(); $time = $time_end - $time_start; echo "Query completed in $time seconds<br/>n"; echo "You got the page"; 脚本输出: wait_timeout = 2 Query completed in 8.0005459785461 seconds You got the page 我的配置 mariadb-server-5.3.5 php5.3.6 为了迫使MySQL在一定时间后超时查询,我需要做些什么? 解决方法
wait_timeout和interactive_timeout都是连接断开之前不活动的时间.因此,连接必须处于空闲状态(不运行查询)才能被删除. MySQL SLEEP()不计算,因为您正在运行查询.
您将不得不手动终止长时间运行的查询(没有设置让MySQL为您执行此操作).你可以编写脚本.使用SHOW PROCESSLIST(或外部工具,如Innotop)和KILL. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |