Every now and then you end up having to develop on a Windows box. Here are some handy hints for getting your cron jobs up and running.
The user interface for the Scheduled Tasks in Windows can be found at Start > Programs > Accessories > System Tools > Scheduled Tasks.
For performing cron jobs on webpages I recommend that you get the following binary: WGET for Windows
Now to setup your cron job:
- Double click Add Scheduled Task
- Click Next to skip past the intro
- Browse to program you wish run. Now you can use FireFox, Internet Explorer or indeed any other programme here. You could even run a batch script – more on this later. For web based invocation (calling a webpage over http etc) I recommend you use Wget though as it will not remain open after execution and it will use less resources. Of course if you have a PHP CLI script then you can invoke the PHP binary. I am going to focus on Wget and FireFox for the moment. After choosing the application click next.
- Give your task a name and choose the regularity with which you wish the task to be performed.
- Pick the time, start date and additional break points ie should it run on weekdays only?
- Now you need to enter the username and password of the user this application will be run as. It goes without mentioning that running FireFox as Administrator is a bad idea. Next.
- Check the “Open advanced properties for this task when I click Finish” checkbox and click finish.
You are now presented with what looks like a standard Windows file property dialogue but there are a few extra options. You will arrive on the Task tab.
- In the Run input box we can now specify the file we would like to be opened by our Application. This should be the full URL:
http://example.org/my_cron_job.phpfor both FireFox and Wget. For Wget only add the following onto the end of the run command: ” -r”. This will cause Wget to clobber the file it downloads instead of making copies: Wget Manual see ‘-nc’
–no-clobberSo once your done your Run should resemble this
C:wget.exe http://example.org/my_cron_job.php -r
- On the Schedule tab you can change the regularity of the Task with more granularity using the Advanced button. And you can have multiple schedules for the same Task.
- The Settings tab I would set the Stop the task if it runs for: 00 hour(s) 1 minute(s).
- Click OK.
Once back in the list of Scheduled Tasks folder you can right click on the Task and choose Run to see if it works as expected.
I would like to have a few batch scripts that I could run like you would have cron.daily and cron.hourly in Linux. Then you only need one scheduled task and you can run multiple jobs for each time break down. Maybe another time.