How to write php to update 500 pieces of data each time
仅有的幸福
仅有的幸福 2017-06-12 09:20:44
0
4
929

Please give me a pseudocode
Update 500 pieces of data once in each loop

仅有的幸福
仅有的幸福

reply all(4)
黄舟

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]['某值'] = ‘某值’;
    }
}
}
学习ing

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

曾经蜡笔没有小新

First determine the total number of times, and then use the for loop to get 500 updates each time

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template