Skip to content Skip to sidebar Skip to footer

Timely Interval To Retrieve Data From Db, And Stop When The Data Arrives

I'm a newbie, so be kind :) What is the simplest solution for checking for, retrieving and using newly received data from a mysql database? The database is being updated from an e

Solution 1:

My solution in the end is indeed in php and not ajax (there is really no need for client side in this situation).

Here's the outline:

<?phpwhile (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 $resultbreak; // get out of the loop
            }
        }
    ?>

Solution 2:

Don't use such logic on client side. JavaScript could be easily manipulated/changed. Someone could replace the interval with much shorter one and stress the server. Read about Comet, use it for waiting for the results from the server. On the server side do all the logic: implement database polling (with interval, as you wish), and, when needed, push the data to the browser/stop polling/do whatever you want.

Post a Comment for "Timely Interval To Retrieve Data From Db, And Stop When The Data Arrives"