A Cron job is what you are looking for. You can search on SO/Google/etc. for how to create/setup a Cron job.
How to periodically run/refresh a PHP counter script on a server with no user interaction (if possible)
Question
I've written a PHP script that gathers all the data from an IceCast stream and stores it in an array. I want to measure how many listeners the stream has ever five minutes. Is there a way to remotely run the script so that it "refreshes" every five minutes and sticks the number of listeners into a database? Thanks!
Solution
OTHER TIPS
I have used following snippets to periodically run a script.
The main advantage of it is that run after $min minutes
(configurable) after finish the current process. That cannot be achieved with cron that run exactly each X time. See the differences? In this way you can be sure of wait a given amount of time between processes.
Maybe is not exactly what you want but I would like to share this useful technique.
script_at.php file:
function init_at()
{
// my code
runNextPlease();
}
function runNextPlease()
{
$min = 5;
exec ("at now + $min minutes -f " . PATH_TO_SOURCE . "script_at.sh", $output, $out);
my_logger("at return status: $out");
}
script_at.sh file:
#!/bin/bash
/usr/bin/wget -c -t0 -o /dev/null -O /dev/null http://domain/script_at.php