<?php
header('Content-Type: text/html; charset=utf8');
$dbhost = '192.168.1.23';
$dbuser = 'demouser01';
$dbpass = 'demo*PW';
$dbname = 'testdb1';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection');
mysql_select_db($dbname);
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER_SET_CLIENT='utf8'");
mysql_query("SET CHARACTER_SET_RESULTS='utf8'");
if(isset($_POST['start'])) {
$chi = 'chiiiii';
$id = 1;
for ($i = 1; $i <= 99999999999; $i++) {
$eng = substr(str_shuffle(str_repeat("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 5)), 0, 1024);
$math = substr(str_shuffle(str_repeat("1234567890", 6)), 0, 16);
$sql = "INSERT INTO test_tb (id,chi,eng,num) VALUES (".$id.",'".$chi."','".$eng."',".$math.")";
$result = mysql_query($sql) or die('MySQL query error');
$id++;
}
$id = 0;
sleep(60);
mysql_close($conn);
} else if(isset($_POST['stop'])) {
mysql_close($conn);
}
?>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<input type="submit" name="start" value="Start Insert">
<input type="submit" name="stop" value="Stop Insert">
</form>
网站上有两个按钮,插入重复插入一条记录,停止插入。但是,我尝试使用 MySQL 关闭连接,它会在 PHP 中停止运行,但活动仍然存在。插件仍在继续执行。如何解决问题?谢谢。