how data is generated without user activity has never been quite clear to me. Let’s say I’m running a lottery and people can check the winning ticket number online. This random number has to be automatically generated at a specific time and should be the same for every visitor. How is that done?
I figured I could use a PHP script which retrieves the previous number and check whether it is, say, over 7 days old. If it is, the script would then generate a new number and store it, so it will be retrieved when other users visit the page, in which case the number would simply be shown as it’s not over 7 days old.
This method of doing things might cause trouble with multiple users both trying to access files at the same time or overwriting data which is simultaneously generated by/for another visitor. I think it would be better if the number could be generated and stored independently of user activity, so the PHP script’s only task is to read it.
Any ideas would be much appreciated!
P.S: I’m using simple webhosting and do not physically have access to the server, can’t leave a .bat or .exe running I guess. Also, tags might be somewhat inaccurate as I don’t know what I should be using to tackle this problem.
Use some kind of scheduler to execute the task at a given time. One such scheduler is called
cronand is installed in most Unix-like environments.There are also cloud-based schedulers, which will call an URL of yours at the schedule you choose.
If your hosting provider doesn’t provide this service (most do!), try searching for
online cronjob,hosted cronor similar (a “cronjob” is one job executed by the cron daemon).