How to easily and simply, schedule a cron job in PHP -- Rails has BackgroundRB.. Thanks for your help!
views:
555answers:
4Most website control panels (assuming you've got cPanel or something similar running) include a crontab application. If you're on shared hosting ask your host about this.
If you're on a dedicated server and have installed cron then have a look at the crontab syntax. These commands go in crontab
, usually in /etc
on *nix.
You're conflating a language with a framework. PHP doesn't have a cron scheduling any more than Ruby does. If you're using a PHP framework or cms however, there is likely some utility for cron tasks.
Here is a useful link if you have control over the machine. http://troy.jdmz.net/cron/ If you have shared hosting, there's probably some tool they'd give you for cron jobs; ask them or look in the knowledge base.
Here's a semi-PHP solution to add to a crontab:
$cmd = 'crontab -l > /tmp/crontab.bak'; // preserve current crontab
$cmd .= ' && echo "*/5 * * * * /foo/bar" >> /tmp/crontab.bak'; // append new command
$cmd .= ' && crontab /tmp/crontab.bak'; // update crontab
$cmd .= ' rm /tmp/crontab.bak'; // delete temp file
exec($cmd); // execute
There is PHP-Resque, a PHP port of the queue&background process framework written by GitHub guys.