Please give me a pseudocode
Update 500 pieces of data once in each loop
黄舟2017-06-12 09:22:44
Push the records to be updated in batches into the queue, and then consume the queue. Remember to log. We make queues to execute tasks in an orderly manner and ensure that each update is completed.
怪我咯2017-06-12 09:22:44
I don’t know the specific usage scenario, so I don’t dare to fool around with it
Baby
After taking out a large array
$res = [];
for ($x=0; $x<=($res/500); $x++) {
$res = array_slice($res,0+500*$x,500);
if($res)
{
update table set=value where id($res['id']);修改数据库
foreach($res as $key=>$value)
{
$res[$key]['某值'] = ‘某值’;
}
}
}
学习ing2017-06-12 09:22:44
1. If it is the same table and has certain same characteristics, some data can be updated in batches using where conditions
update table set count=count+1 where id > 1 and id < 501
2. If the tables are different and the logic is different, then you need to consider whether it will time out. If the request does not require user payment, you can use fastcgi_finish_request
to interrupt the user request and continue to execute the code, or take the form of a scheduled task
曾经蜡笔没有小新2017-06-12 09:22:44
First determine the total number of times, and then use the for loop to get 500 updates each time