84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
Please give me a pseudocodeUpdate 500 pieces of data once in each loop
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.
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]['某值'] = ‘某值’; } } }
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
fastcgi_finish_request
First determine the total number of times, and then use the for loop to get 500 updates each time
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.
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
1. If it is the same table and has certain same characteristics, some data can be updated in batches using where conditions
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 taskFirst determine the total number of times, and then use the for loop to get 500 updates each time