Random numbers, my personal favorite 😉
Well, the "best" way is to set up a daemon in crontab. If you don't know how/want/can't do that, or you prefer a different method, here is my little home-brewed method.
First, stick your code inside a loop. Have the loop check a file or a value in your database to continue.
At the end of your code, have your script stuff the date/time into your database/file (we'll just say database). This is the value the start of your script will check for.
If that date is 24 hours or more earlier than the date it finds, have it execute the loop.
On any page that displays/uses that data, you'll need to include this "if" loop there.
For all non-time intensive purposes, it will appear to the user that you just have a daemon set up to do your dirty work.
The other possibilty is using sleep() in various ways, but it's not as good or dependable.