Seek the solution of the concurrent heroes ....

Source: Internet
Author: User
Because there is a piece of code to use while loop code, once the data volume is large, it will fail, the solution ah ....

while ($rows = $query->fetch_array ()) {

if($rows['mingxi_1']=='1'){    $ds = Ssc_Ds($rs['ball_1']);    $dx = Ssc_Dx($rs['ball_1']);    if($rows['mingxi_2']==$rs['ball_1'] || $rows['mingxi_2']==$ds || $rows['mingxi_2']==$dx){             $msql="update c_bet set js=1 where id='".$rows['id']."'";        $mysqli->query($msql) or die ("修改订单状态失败!!!".$rows['id']);        //给会员账户增加奖金        $msql="update k_user set money=money+".$rows['win']." where uid=".$rows['uid']."";        $mysqli->query($msql) or die ("修改失败!!!".$rows['id']);    }else{        //注单未中奖,修改注单内容        $msql="update c_bet set win=0,js=1 where id=".$rows['id']."";        $mysqli->query($msql) or die ("修改失败!!!".$rows['id']);    }}

Reply content:

Because there is a piece of code to use while loop code, once the data volume is large, it will fail, the solution ah ....

while ($rows = $query->fetch_array ()) {

if($rows['mingxi_1']=='1'){    $ds = Ssc_Ds($rs['ball_1']);    $dx = Ssc_Dx($rs['ball_1']);    if($rows['mingxi_2']==$rs['ball_1'] || $rows['mingxi_2']==$ds || $rows['mingxi_2']==$dx){             $msql="update c_bet set js=1 where id='".$rows['id']."'";        $mysqli->query($msql) or die ("修改订单状态失败!!!".$rows['id']);        //给会员账户增加奖金        $msql="update k_user set money=money+".$rows['win']." where uid=".$rows['uid']."";        $mysqli->query($msql) or die ("修改失败!!!".$rows['id']);    }else{        //注单未中奖,修改注单内容        $msql="update c_bet set win=0,js=1 where id=".$rows['id']."";        $mysqli->query($msql) or die ("修改失败!!!".$rows['id']);    }}

1. Can I get the full version of the code? SQL is not reluctant to take out?
2. Visual inspection is too many result sets of SQL, memory may overflow, and operation may be time consuming
3. Solution: Solve with Redis queue or MySQL queue

The cycle operation of the affirmation can no longer be written in the program like this ah ... You can create a new SQL table as a queue, or make a queue directly with Redis. And then open a new service or script that specifically handles this task.

It is estimated that the processing speed is too slow, causing the server to fail to respond to new requests. From the code point of view, you have a problem with the processing mode, it is best not to use a loop one processing orders, if possible to use the database to solve, such as the stored procedure is relatively fast.

Your $rs should be a large array, and you will be inefficient in using MySQL queries in the loop.
It is recommended that you run PHP with a CLI pattern to handle asynchronously

Don't want to use the queue to give you a very simple and violent multi-process thinking

For the largest query result set based on the ID modulo for the shunt multi-process processing, the idea is similar to the following pseudo-code

        for ($i=1;$i<=100;$i++){            if($i%5==0){                echo 'mod 1 : '.$i.'
'; } if($i%5==1){ echo 'mod 2 : '.$i.'
'; } if($i%5==2){ echo 'mod 3 : '.$i.'
'; } if($i%5==3){ echo 'mod 4 : '.$i.'
'; } if($i%5==4){ echo 'mod 5 : '.$i.'
'; } }

For all IDs according to the amount of data to take the mold split, as you are all taken out to split, or directly open 5 PHP process SQL statement query when the split, according to your business logic to analyze the specific.

SQL statement split 5 process processing is similar to the following:

SELECT * FROM member where member_id%5=0;SELECT * FROM member where member_id%5=1;SELECT * FROM member where member_id%5=2;SELECT * FROM member where member_id%5=3;SELECT * FROM member where member_id%5=4;

Can be in while (1) {
Take out part of data processing at once and then step out of the loop after the processing is completed
}

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.