3
To perform certain function in a time interval.
3
To perform certain function in a time interval.
9
PHP doesn’t have it native. Nor does it make sense. When you need something like this and PHP applications rarely need it, and it is common for programmers to opt for a wrong mechanism for their need, it is better to schedule task in the operating system to call the script desired. Leaving something running and firing will not work well, or even work, in a web environment there is a short time limit that the script can rotate
But if you want to know, you can create a function to do that, something like that:
function setInterval($callback, $milliseconds) {
$seconds = (int)$milliseconds / 1000;
while (true) {
$callback();
sleep($seconds);
}
}
I put in the Github for future reference.
But it’s too bad to do it, don’t do it.
Browser other questions tagged php javascript setinterval
You are not signed in. Login or sign up in order to post.
Easier would be to run a PHP from time to time, by linux crontab or windows scheduler.
– Bacco
It would help a little if the question brought more context e.g. what kind of activity is intended to do regularly.
– epx
@epx Thanks for your attention, but this question is more than 3 years old. I can’t remember the context in which I made it.
– Seu Madruga