What should I use to easily manage cron jobs in a PHP project?

I want simple cron-like management in a PHP project to have some things that I would like to have:

  • The php work worker is just a script that is placed in some subdir directory inside the project
  • the project root has a subtree, for example / cron / daily, / cron / month ... etc., which contains all the workers
  • no need to mess with crontab with every worker added.
  • all scripts are run by something like execution parts with the appropriate frequency, and their corresponding output is written to separate files, such as /var/log/projectname/cron/daily/somescript.log
  • it would be nice to have / cron / daemon dir containing scripts that should run forever (at least), but no more than 1 instance

I had experience with such a planning system in one project and I liked it. It provides a lot of neat things:

  • jobs are project scripts and are located in the project directory, tracked by git.
  • no crontab messing needed. Magazines
  • sorted.
  • demons are easy to create.

I would just use / bin / run -parts in subdirs project / cron, but I was not able to break the logs. And to share logging is a very nice feature.

So, I just thought that such systems were created many times before, is there a ready-made solution for a PHP project? In fact, these are just a few of the smarter spare parts. Should just write it again?

PS There are many more solutions for a particular lineup, such as Gearman. They are great, but this question is related to the easy solution of the cron project work tasks.

+5
3

. Jenkins ( Hudson) PHP. , (jabber, email ..), . , ..

, PHP, CLI, , Jenkins .

PHP Jenkins Hudson:

http://blog.shupp.org/2011/03/15/organizing-php-batch-jobs/

+2

Periodic - , CRON, PHP. , , , .

0

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 *'));
-1
source

All Articles