Periodic - A PHP based cron utility
Periodic is a fully unit tested PHP based task runner. It is supposed to deliver a basic implementation for managing all kinds of recurring tasks and events inside your web application. It has been designed with having all kinds of different web hosting environments in mind. It is capable of running on most shared hosting systems as well as root servers.
Motivation
Kore and me needed some kind of recurring task management system for different projects we are currently working on. I started working on some kind of CronjobIterator which is capable to parse a cron definition -- you might know this definitions from the famous vixie-cron daemon -- and provide an iterable list of timestamps matching this definition. The vcron definition syntax seems to be the most intuitive and widely spread syntax to describe recurring events, therefore we chose it.
As Kore got to the point where he needed something like this in arbit he wrote a design document for it and started discussing it with me. We tried to create a modular and flexible system fulfilling the needs of both our projects. I think we did a good job with that. I finished the CronjobIterator while Kore began writing other base components of it. In the next weeks I am going to implement the cron daemon part of it which will handle forking and parallel grouped task execution.
If you want to take a look at this nifty little tool, you can check out its subversion repository at:
svn://arbitracker.org/arbit/projects/periodicQuestion about vixie-cron
I have one personal question to you. During my readings of the vixie-cron man pages to figure out the exact syntax definition of events, it came to my attention, that the month field allows the number 0-12. If you known what the 0 month in this case is, I would be glad if you could just tell me using the comment function of the blog or sending me a mail. Thanks :).
Dominic on Fri, 30 Jan 2009 04:59:38 +0100
I guess 0-12 is done to allow the value 0-11. The index starts as 0.
Link to commentIn the code.c (line 163 and following, ftp://metalab.unc.edu/pub/Linux/system/daemons/cron/cron3.0pl1.tar.gz) is written:
/* make 0-based values out of these so we can use them as indicies
*/
minute = tm->tm_min -FIRST_MINUTE;
hour = tm->tm_hour -FIRST_HOUR;
dom = tm->tm_mday -FIRST_DOM;
month = tm->tm_mon +1 /* 0..11 -> 1..12 */ -FIRST_MONTH;
Maybe this helps
Jakob on Fri, 30 Jan 2009 06:43:39 +0100
Thanks for the hint. Unfortunately I am still not quite sure about this. Because if the month field is really zero based in the crontab file it would only be defined as a range of numbers between 0-11 and not between 0-12.
Link to commentFor weekdays it is clearly stated that 0 and 7 are the same day (Sunday) and therefore a range of 0-7 is allowed.
I can't find any equally enlightening explanation for the 0-12 month range.
Maybe someone else can shed a little light on this?
greetings
Jakob
Robin Mehner on Fri, 30 Jan 2009 11:59:05 +0100
Hi Jakob,
Link to commentI'm not an expert in C, but looking into the header files of vixie-cron (cron.h in this case) there are definitions for FIRST_MONTH (which is 1) and LAST_MONTH (which is 12).
Weekdays are also defined there, with 0 and 7 as borders.
I think that there is some kind of misleading manual which states this wrong. Where did you read this?
I found some site of another cron projekt which states that they try to handle to 0 as "January of next year", but unfortunately I can't find it anymore.
Hope this helps a litte bit.
Jakob on Sat, 31 Jan 2009 00:07:13 +0100
@Robin: I got the information from the vixiecron manpage(5).
Link to commentI am starting to think this could possibly just a documentation error. I have decided to ignore the problem for now and just support values from 1-12 in the month field. Maybe someone will complain about this and can then tell be definetly what the value zero is supposed to do in this context.
Thanks for all your input :)
greetings
Jakob
Eliot Pearson on Sat, 31 Jan 2009 13:53:37 +0100
I checked the manpage on my system and it had a range of 1-12. So I pretty sure it's a typo. Which distro are you using?
Link to commentmonth 1-12 (or names, see below)
Jakob on Sat, 31 Jan 2009 18:42:15 +0100
Thanks for looking this up. :)
Link to commentI am using gentoo on all of my systems and there it clearly states the following:
field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31
month 0-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)
But if it is defined otherwise in your manpage it really seems to be a typo here.
Besides I still can not see any useful semantical definition in the value zero.
greetings
Jakob