Most of the hosting companies have a time limit for scripts to run. So an infinite loop will not work, or will get your account suspended.
cronjobs are the best way to do it. Just set the script to run in a time interval of your choice and make sure that it doesn't take too long finish execution.