I have a webapplication, written in PHP (Zend Framework) and I’d like to execute a (few) script(s) every once in a while. For example once a day. I know this can be done by using crontab and cronjobs, but not all hostingproviders have these available. Therefor I’m looking for a solution without using the Cronjob.
How do you solve this?
What are the possibilities?
Cron jobs really only offer a few basic benefits: scheduling, execution and logging. These are all things that are pretty easy to replicate in a PHP application…
Step One: Create a table of tasks
You’d need to store:
Step Two: Execution
You have a few options on how to actually trigger the tasks:
No matter how it starts, it would trigger the actual cron code, which decides whether or not there are any tasks to run, and which ones to run.
Step Three: Logging
This one should be pretty simple. Just log what happens during tasks to a file that you can read after to make sure its working.
…
Before running a task, you’d update the previous run date, and after running a task, you’d set the next run date, based on its frequency. The only fallback of this method is that when nobody visits the sites, no cron jobs will execute until the next visitor comes.