Editing Crontab with PHP

software development

#1

Is it possible to edit the Crontab with a php file? I’m working on project that allows users to create schedules in order to have specific information sent to them at specific times. The two methods I’m looking at to do this are:

  1. when the user schedules a send-time, it is entered into the crontab, which will run the proper script at the proper time. This is the thing where I don’t know if it will work, since I haven’t found any information on dynamic automated crontab editing.

  2. when the user schedules a send-time, it is stored and the crontab runs a script every 10 minutes. That script essentially asks: “Is it time yet? Is it time yet? Is it time yet?” over and over until the time for the event actually comes.

For my purposes, editing the crontab would be the easier solution, but I have no idea if it is possible.


#2

It should not be a problem if you are okay with PHP and scripting.
The calendar one-click install uses cron to run a reminder.php script to see if there are any events due for which a reminder email needs to be sent.
The crontab is just a text file that the cron daemon reads so it can be filled from a script.
Try google with dynamic crontab editing and you will see it has been done before.
There is an online cron generator here so it wouldn’t take that much more effort to feed the result back into a crontab.

Mind you for ease of use I think the ‘calendar’ way would be the best option where you could get cron to run a script every minute to check for the presence or not of another script etc…


Norm


#3

Yes. The file that gets submitted to crontab is simply a *nix text file; if you’re at all familiar with handling serial access files it shouldn’t represent much of a fuss.

[quote]I’m working on project that allows users to create schedules in order to have specific information sent to them at specific times. The two methods I’m looking at to do this are:

  1. when the user schedules a send-time, it is entered into the crontab, which will run the proper script at the proper time. This is the thing where I don’t know if it will work, since I haven’t found any information on dynamic automated crontab editing.[/quote]
    Again, the file you submit to crontab is just a (mildly formatted) text file. The catch with crontab is that submitting a file to the cron daemon for tabbing isn’t cumulative; every time you add a new job you have to re-create the entire file and re-submit it (IOW, you can’t just append the crontab).

Actually, it’s exactly that sort of repetitive procedure that computers are real good for.

It’s possible, but probably not so very desirable. Fiddling with the cron daemon on a semi-constant basis may cause some nuisance, especially if two users are trying to read or write to the crontab file at the same time. Your second method of using the cron daemon to periodically check a multi-user accessible database for some timed event is probably the best and safest way to go. From an administrative point of view, it’s much easier to pinpoint a problem in a database than to sift through (what might potentially be) a bulky textfile full of cron entries.