Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Implementing a Scheduled Task

Go to End

10 Posts   6277 Views


18 May 2009 at 12:14pm (Last edited: 18 May 2009 12:19pm), Community Member, 75 Posts


I'm wondering if someone can give me some pointers on implementing a scheduled task in SS. I've never worked with scheduled tasks before so I am very new to this.

The scenario is that I have a product class like so:


class Product extends Page {
    static $db = array(
        'Price' => 'Currency',
    static $has_one = array();

    function updatePrice(){
        loader = new Product_Updater();


class Product_Controller extends Page_Controller {

class Product_Updater extends CSVBulkLoader {



I have an updatePrice() method that goes through and updates price of products in the database from a CSV. This is all working fine. Now what I need to do is implement a scheduled task so that this process will run once a day at a specific time (say 2am).

How would I go about doing this? Would it be something like:

class MyTask extends DailyTask {

    function process() {

I'm not sure how exactly the task scheduler in SS works, how I would register tasks, set times, and check the output. I would appreciate any help and guidance with this.


18 May 2009 at 6:12pm Community Member, 901 Posts

Did you read the documentation about scheduled-task?
Your class looks fine, you just need to call the URL or cli-script.php at the desired interval using a cron-job (or similar). Some hosting providers allow you to setup your own cron-jobs. If that's not possible, you could use a service like (disclaimer: I never used that service before, it just popped up after a google search)


18 May 2009 at 8:04pm Community Member, 75 Posts

Hi banal,

Thanks for the reply - yes I did look through the documentation but as I've never implemented something like this before it makes me nervous. It wasn't clear to me how the scheduling would work.


18 May 2009 at 8:31pm Community Member, 901 Posts

Hi pingu

In that case, you best get familiar with cron jobs first. Just search for "cronjob tutorials" or anything similar and you'll find lots of information on that behalf. If I were you, I'd start with a simple script to test and then later move to the SilverStripe way of doing things.


26 May 2009 at 3:38pm (Last edited: 26 May 2009 11:06pm), Community Member, 75 Posts

Okay so I've done my research and implemented my scheduled task which is working fine if I test it manually.
However when I try to run it using crontab I'm having some issues:

1. If I try using wget (wget, it's failing at login. Do I need to pass in login parameters somewhere??
2. If I try using cli-script.php (cli-script.php /DailyTask) I'm getting a bunch of warnings and errors

What's the best way to call the scheduled task?
Would appreciate any guidance with this


26 May 2009 at 6:24pm Community Member, 901 Posts


I'd say wget is the easiest way. I never used the SilverStripe tasks myself, but requiring a login for it seems to be quite a bad decision by the developers... that won't work with a cron-job.
Maybe you just put the wrong URL in the cron-job? The docs ( says:

Even with your wget call, I'd probably prefix it with http://


24 July 2009 at 9:13pm Community Member, 21 Posts

I'm having the same problem(s) trying to implement the scheduled tasks with a cron job. I wish this were better documented. Anyone make any progress on this?


25 July 2009 at 4:37am (Last edited: 25 July 2009 4:40am), Community Member, 21 Posts

Finally figured it out. For the benefit of anyone trying to use scheduled tasks with cron jobs, here's a fairly complete step-by-step:

1) Create whatever tasks you want to run by extending the appropriate class (see Test your scheduled task via the browser as explained in the docs.

2) Manually create a cron job to execute the task at the desired interval. As mentioned in the thread above, it's wise to get familiar with cron jobs via some tutorials. To create the cron job on the server, you'll need command line access. Assuming you can SSH into the server, do so, and at the prompt type

crontab -e

to open the crontab file. Enter the cron job. Here is an example for the DailyTask:
00 12 * * * /usr/bin/php5-cgi /full/path/to/yoursiteroot/sapphire/cli-script.php DailyTask

The "00 12 * * *" portion tells cron to run the script at noon everyday (change the 12 to whatever hour you want). Notice that I needed to specify the full path to the php executable on the server in order to run cli-script.php as php. You may or may not need this depending on your server settings. Save this file. You should get a message saying something like "installing new crontab file."

3) Finally, I needed to add the _ss_environment.php file to the root of my site in order for the script to execute properly. This wasn't necessary on my local dev server, only on remote dev and live server... not sure why. A difference in the php settings, I guess. You can read about this file at Here is an example of what it looked like in order to work for me:

$_FILE_TO_URL_MAPPING['/path/to/yoursiteroot'] = '';

I think that's it. Good luck.

Go to Top