运行 最多插入查询 5 分钟 MySql
Run Insert queries upto 5 mintues MySql
基本上我有一个MySqltable位置
------ -------------
b_id updated_time
------ -------------
C1 17-5-2014 16:55:35
D1 17-5-2014 16:55:32
还有一个tablelocation_history
------ -------------
b_id updated_time
------ -------------
C1 17-5-2014 16:55:35
C1 17-5-2014 16:55:34
C1 17-5-2014 16:55:33
D1 17-5-2014 16:55:32
D1 17-5-2014 16:55:31
D1 17-5-2014 16:55:30
此处位置table的数据将被插入一次并不断更新。然后 location_history table 中的数据不断插入更新的新记录。
我们可以在位置 table 中找到最新的更新时间。对于 C1,它是 16:55:35 和 D1 16:55:32。这些插入是随机的
我想要的是 - 基于位置 table 的最新更新时间,我想 运行 在 location_history table.[= 插入查询 5 分钟14=]
假设,我有新的 b_id -> E1,它在 table 位置有 updated_time 16:55:37。所以这是最新的。因此,最多 5 分钟,INSERT 查询应该继续在我的 location_history table 上执行 b_id=E1
在这种情况下,每次插入位置 table 后调用此代码(使用触发器或仅在 PHP 脚本中调用)
我想你有 PHP >= 5.3.0
...
$check_time = time();
$up_to_time = strtotime("+ 5 minutes");
while( $check_time < $up_to_time ){
$check_time = time();
$updated_time = date("Y-m-d H:i", $check_time);
// $b_id is an inserted id got from INSERT into location table
$sql = "INSERT INTO location_history ( b_id, updated_time )
VALUES( $b_id, '$updated_time');
mysql_query($sql) or die(mysql_error();
sleep(50);
}
基本上我有一个MySqltable位置
------ -------------
b_id updated_time
------ -------------
C1 17-5-2014 16:55:35
D1 17-5-2014 16:55:32
还有一个tablelocation_history
------ -------------
b_id updated_time
------ -------------
C1 17-5-2014 16:55:35
C1 17-5-2014 16:55:34
C1 17-5-2014 16:55:33
D1 17-5-2014 16:55:32
D1 17-5-2014 16:55:31
D1 17-5-2014 16:55:30
此处位置table的数据将被插入一次并不断更新。然后 location_history table 中的数据不断插入更新的新记录。
我们可以在位置 table 中找到最新的更新时间。对于 C1,它是 16:55:35 和 D1 16:55:32。这些插入是随机的
我想要的是 - 基于位置 table 的最新更新时间,我想 运行 在 location_history table.[= 插入查询 5 分钟14=]
假设,我有新的 b_id -> E1,它在 table 位置有 updated_time 16:55:37。所以这是最新的。因此,最多 5 分钟,INSERT 查询应该继续在我的 location_history table 上执行 b_id=E1
在这种情况下,每次插入位置 table 后调用此代码(使用触发器或仅在 PHP 脚本中调用)
我想你有 PHP >= 5.3.0
...
$check_time = time();
$up_to_time = strtotime("+ 5 minutes");
while( $check_time < $up_to_time ){
$check_time = time();
$updated_time = date("Y-m-d H:i", $check_time);
// $b_id is an inserted id got from INSERT into location table
$sql = "INSERT INTO location_history ( b_id, updated_time )
VALUES( $b_id, '$updated_time');
mysql_query($sql) or die(mysql_error();
sleep(50);
}