I am wanting to add a section in my php application to add / remove scheduled tasks.
Something similar to what they use in vBulletin Forum.
http://ryanfaerman.com/php-crontab-manager/
is a php class that lets you access a crontab from PHP using a class.
I believe vBulletin "fakes" cron jobs. Any user which accesses the page executes code which checks to see if any tasks need to be run.
If however, no users visit the website, none of the cron jobs will execute, the method is 100% reliant on page views.
Also, to prevent delayed page rendering on users who execute the cron jobs they are executed after the page has been rendered.
Again, this is just what I think is happening, I haven't looked at the code myself.
Hope this helps.
Here's a PHP crontab class:
http://www.kavoir.com/2011/10/php-crontab-class-to-add-and-remove-cron-jobs.html
Use the methods to add, edit or remove cron jobs.
Here is my solution :-)
Sample from command line:
bin/cronman --enable /var/www/myproject/.cronfile --user www-data
Click for more: php-crontab-manager
If you don't have the exec()
function enabled, you have to rely on manually setting at least one cron job via some interface and then managing individual jobs in your script.
What I do for example is this
heartbeat.php
which is executed every minutecrontab
and checks if there is any row (job) with time_to_process <= NOW()
crontab
tablerun()
method and I only call $cronJob->run()
to make it runcrontab
table once it finishesA good example is to reset daily views on some items.
The job is scheduled at May 1, 2010 00:00. Once the job ran, it schedules itself for the next day automatically.
You can then implement automatic reset of failed jobs and many other features from within PHP.