2

Hi all I am using Zend framework for my PHP project. Basically I have few actions that I want to run automatically. I will be using a cron job to do the trick. The cron job will run a php script file.

Till now everything seems normal. Now I have created a table in my database and have stored the actions that I need to run in it. For example I need to do the following:

1-Create a sample file (5 times).

2-Upload all sample files (1 time).

3-send mail (continuous).

So I will store in my table the controller and action for (creating a sample file) and set its repeating time to 5 and set also its execution time. The same will be done for the other two actions.

Now the script file is run every minute. In the script file I will select all records that from the table that have an execution time equal to the current time then run them.

Now to make things just clear this system actually works but I was thinking about a better or improved scheduler techniques. Storing the scheduled actions in a table sound like a good idea but I was wondering if there was a superior approach ?!

Songo
  • 5,618
  • 8
  • 58
  • 96
  • How often are they changed, and via what interface? – alex Mar 13 '11 at 12:48
  • well I have a UI screen for controlling the scheduled tasks. Simply the user can choose from a drop down the task which he like to add to the table and he specifies the time and repetition of the task. The user can view all the tasks in the table and can modify or delete any of them. The tasks themselves are defined once and are loaded in the dropdown. The user can then choose any number of tasks to add to the cronjobs table in the database. The frequency of the changes can depend on the business need as we are still in the development phase. – Songo Mar 13 '11 at 20:58

2 Answers2

0

This seems fine to me. You're using a cron job to run a PHP script which selects matching records to be executed from a database table. Storing data, as long as it's in a normalised form in the database, will be an efficient way. Monitor the load on your server and adjust from there if you need to.

Kat Cox
  • 3,469
  • 2
  • 17
  • 29
Gary Corbett
  • 139
  • 4
  • well I was looking for new ideas because I was asked to make the cron jobs system more generalized so it can work on any application or database. That's why I thought maybe there was something better to do! – Songo Mar 13 '11 at 21:04
0

My aproach is have a cyclic script that "empties" (set jobs as "finished") the table. And there are more CRONs with different timing that fill the table. So the workflow is like this:

minute: nothing to do
minute: nothing to do
hour: added export feed update
minute: export feed update finished
minute: nothing to do
minute: nothing to do
minute: nothing to do
minute: nothing to do
...
minute: nothing to do
five_hours: added "clear the cache"
minute: clear cache finished
minute: nothing to do
minute: nothing to do
...
Tomáš Fejfar
  • 11,129
  • 8
  • 54
  • 82