I want to run SQL query every day.
Now I read about the sleep
function.
I understand that the script runs until it get to the sleep function, and than sleep some seconds and then wake up again, so I did for testing this code:
for ($i = 1; $i < 3; $i++) {
echo date("i:s");
sleep(10);
}
The problem is that I dont get any output until go through 20 seconds.
And I dont need that, I need that the script run, than sleep 10 seconds and than run again?
From what I understand its only happens with output, I mean the behavior of the script above is to echo in the first iteration but save the output and then when the two times over output all.
So if I'm right, If I run a SQL query it will run the first iteration and than sleep 10 sec and than run again yes?
Also I have a question, whats happen if I exit the page, the script still keep running? or when I leave the page its kill the script?
I want to run something like that:
function delPosts () {
sleep(24 * 60 * 60);
$mysqli->query('DELETE FROM posts WHERE date < "SOME DATE"');
delPosts();
}
delPosts();
Tanks for helping