There is the windows task scheduler which is very simple to use. I don't think you will get 10-second-by-10-second resolution .. You would most likely have to schedule it per minute.
You could also schedule a task scheduler (or cron, for linux) item to run it, say 3-4 times in a row, every minute:
for($x = 0; $x < 4; $x++) {
yourFunction();
sleep(10);
}
So, in that way, you have a script that is going to execute it 4 times per minute, although, not every 10 seconds precisely. Remember if you do it every 10 seconds 6 times, that this will be over 60 seconds since your script will take time to execute too, and you will have overlap.
If you use the task scheduler method or above method, I would write a "lock" so that if the task scheduler is running a previously started check script, a secondary will never run, such as:
if(is_readable('is_running')) {
die("Already have one running");
}
file_put_contents('is_running', date('r'));
// at the end of the script, remove is_running since it won't be running anymore
unlink('is_running');
The date('r')
so if there is any problems, you can see the last time the lock was written by opening it in a text editor. Once again, unless you do this very precisely, you could end up with (1) a script that runs except once every minute, there will be two scripts running, possibly leading to a slow avalanche of a high number of processes (2) if you use the lock, it could end up running every 10 seconds, every other minute, in the case the lock lasts for a blink of an eye more than 60 seconds... (3) who knows what else ... Which is why in my example, I suggest just running it 3-4 times every minute, separated by a 10 second gap if you really need to to run more than once a minute. (This can STILL cause issues if your script takes a relative long time, so once again.. )
Another method, which is possibly even more prone to issues is to use a long-running PHP script on your windows server that does something like:
while(1) {
yourFunction();
sleep(10);
}
However, this is unreliable as the process will go down (die) occasionally, you will need to make sure it starts on boot, and also deal with a black box running your command line script all the time on the server. Also, in the long-running process case, you might additionally need a secondary script to check that it is running OK every minute or so.
Lastly, and I've used this method a lot more on servers that are going to be heavily loaded... For example, say you know you are getting more than 1 hit every 10 seconds, you could introduce probability in every php script (say, as include, use something like):
if(mt_rand(1,100) < 10) {
yourFunction();
}
Or my preferred method on heavily loaded sites is to use a memory store like apc, redis, or memcache (which I would of already been using, since it's a heavily loaded site) and simply store the "last run" time and if it was more than 10 seconds ago, immediately update the run time and then run the function, pseudo e.x.:
if($yourStore->get('last_garbage_collection') < (time() - 10)) {
$yourStore->set('last_garbage_collection', time());
yourFunction();
}
The last run time could also may be stored in mySQL, Sessions (for a per-user garbage collection, check script, whatever), or whatever.
So, as far as Windows, there really isn't a great way to do any of it. My suggestion would be without a doubt a task scheduler/cron to just run every minute (Do you really need to check it every 10 seconds?), or the last method with a garbage collection time, if you must have the 10-second resolution, it is a heavily loaded site with dozens of requests per second, or more, at all time, and you are aware that still may not run all of the time, break, or worse.