i must call a php function every second
if i place it in a php file it runs a few times every call php file when calling an user
index.php
//code that i want run everysecond (or a few second) $bitsqlz = "SELECT id FROM tasks where id ='$todoid' and state='0';"; $dataz = mysqli_query($con1,$bitsqlz); while ($rowz= $dataz->fetch_assoc()) { $todoid= $rowz["id"]; //dont know how but many users can come here even i set state = 0 below before all codes // and same task runs a few times $dataupd = mysqli_query($con1,"update todos set state=1 where id='$todoid'"); // proecess bla bla bla... }
or must i call it in server side ? (i dont know what is right way and how to make it runs in server side maybe linux can have a program for this. like schuled tasks. )
Advertisement
Answer
You can do an infinite while whith an sleep() of 1 second. But remember to increase the set_time_limit() and use “break” to end the loop.
And if you need to execute a PHP script from the server site on Linux, you can execute it typing “php index.php”.