Reputation: 51
I want a simple cron-like management in PHP project there are some things I would like to have:
I've had experience with that kind of scheduling system in one project and loved it. It provides a number of neat things:
I would just use /bin/run-parts on project /cron subdirs, but didn't manage to split logs as I wanted. And splitted logging is very nice feature to have.
So, I just thought this kind of systems were created many times before, is there any ready to use solution for PHP project? Basically it's just some more smart run-parts equivalent. Should just write it once again?
P.S. There are many more job-queue specific solutions like Gearman. They are great, but this quesion is about project cron jobs lightweight solution.
Upvotes: 5
Views: 3173
Reputation: 12935
Use this function:
function parse_crontab($time, $crontab)
{$time=explode(' ', date('i G j n w', strtotime($time)));
$crontab=explode(' ', $crontab);
foreach ($crontab as $k=>&$v)
{$v=explode(',', $v);
foreach ($v as &$v1)
{$v1=preg_replace(array('/^\*$/', '/^\d+$/', '/^(\d+)\-(\d+)$/', '/^\*\/(\d+)$/'),
array('true', $time[$k].'===\0', '(\1<='.$time[$k].' and '.$time[$k].'<=\2)', $time[$k].'%\1===0'),
$v1
);
}
$v='('.implode(' or ', $v).')';
}
$crontab=implode(' and ', $crontab);
return eval('return '.$crontab.';');
}
var_export(parse_crontab('2011-05-04 02:08:03', '*/2,3-5,9 2 3-5 */2 *'));
var_export(parse_crontab('2011-05-04 02:08:03', '*/8 */2 */4 */5 *'));
Upvotes: -1
Reputation: 46
We've taken a slightly different approach at my current job. We use Jenkins (formerly Hudson) for our PHP related scheduling needs. It's nice because you can leverage the existing infrastructure for notifications (jabber, email, etc), and it sits along side our other build jobs for code releases. There's also the ability to watch console output in real time, get transcripts of every run, etc.
I documented the way we organize our PHP jobs recently so that we can easily leverage our application framework from CLI, which is how Jenkins interfaces with the jobs.
Here's the post about organizing PHP batch jobs for use with Jenkins or Hudson:
http://blog.shupp.org/2011/03/15/organizing-php-batch-jobs/
Upvotes: 2
Reputation: 870
Periodic is a CRON compatible task manager written in PHP. In order to make it work like you desire it, there will still some work to be done, but it should give you a good basis.
Upvotes: 0