我是个新手,所以要友善:)
检查、检索和使用mysql数据库中新接收的数据的最简单的解决方案是什么?
正在从外部api更新数据库。理想情况下,我会得到它,因为它到达,但使用间隔也可以工作。
在第一次迭代中,如果同时没有新数据,则每5分钟执行一次-对数组的下一个条目执行一个操作,这可能会导致在接下来的5分钟内更新数据。但我想确保在收到新数据时停止所有操作,只需在php中执行一些操作。
最简单的解决方法是什么?php与jquery/ajax?
我建议的解决方案在jquery中:

        <script>
            var newdata = false;
            if(newdata === false){
                setTimeout (function(){
                    $.each(array, function(){
                            $.post('checkdb.php',data,function(resp){
                                          if(resp){
                                          newdata=resp;
                                          return newdata;
                                          }
                                          else{
                                          $.post('doaction.php',data);
                                          // cause a potential update within the next 5 min
                                          }
                            });
                    });
                }, 300000);
            }
            else{
                // move newdata back to php and (then) do something with response
            }
        </script>

谢谢!:)

最佳答案

最后,我的解决方案实际上是用php而不是ajax(在这种情况下确实不需要客户端)。
这是大纲:

    <?php
        while (something is true){
            //do stuff

            flush(); // execute the stuff you did until now
            sleep(300); // wait 5 min
            // now check database and retrieve new data, if any, and insert into $result

            if (isset($result)){
                //do stuff with the $result
                break; // get out of the loop
            }
        }
    ?>

10-04 22:17
查看更多