To setup a Windows machine to run cron.php at a specific time follow the specific instructions below. This can be useful if you are not familiar with Linux/Unix, or if your web host does not offer the ability to run cron jobs; you can run them remotely from your own computer.
Note: These instructions were written for Windows XP but should be similar in other versions of Windows.
Creating a Scheduled Task
- Open Scheduler
- Go to Start > Programs > Accessories > System Tools > Scheduled Tasks
- Double-click Add Scheduled Task
- The Scheduled Task Wizard will appear. Click Next.
- Select the program to run. Choose your browser from the list (for example, Internet Explorer or Mozilla Firefox). Click Next.
- Give the task a Name, such as Drupal Cron Job, and choose the Frequency with which to perform the task (for example, Daily)). Click Next.
- Choose specific date and time options (this step will vary, depending on the option selected in the previous step). When finished, click Next.
- Enter your password if prompted. Change the username if required (for example, you'd like the task to run under a user with fewer privileges security reasons). Click Next.
- On the final page, select the checkbox Open advanced properties for this task when I click Finish and click Finish.
Configuring the task
- Go to the task's setting page either by checking the checkbox at the end of the last step, or by double-clicking on the task.
- In the Run box, after the text that is there now (for example, C:\PROGRA~1\MOZILL~1\firefox.exe), enter a space and then type the address to your website's cron.php page in double quotations (for example, C:\PROGRA~1\MOZILL~1\firefox.exe http://www.example.com/cron.php
- To set a frequency more often than Daily (for example, hourly), click the Schedule tab, then click Advanced. Here you can set options such as Repeat task, every 1 hour for 23 hours. Click Ok when finished.
- Change the start time on the task to one minute from the current time. This will allow you to test the task and make sure that it is working.
- When all settings have been configured to your liking, click Apply and OK (note: you may be prompted for your password)
Another way to perform the above commands is by using the schtasks (or at in Windows 2000) command from the command line. To duplicate the example above, which runs Firefox hourly to execute http://www.example.com/cron.php, open a command prompt (Start > Programs > Accessories > Command Prompt) and enter:
schtasks /create /tn "Drupal Cron Job" /tr "C:\PROGRA~1\MOZILL~1\firefox.exe http://www.example.com/cron.php" /sc hourly
Enter your password if prompted.
Using wget for Windows to run cron
If for whatever reason you'd rather not deal with a browser window popping up on the machine, you can use wget, the Windows port of which works more or less the same as it does in UNIX. curl and lynx also have windows ports but wget is probably the easiest to set up and use.
Follow the steps for Creating A Scheduled Task above, except select wget.exe as the program to run (you may need to click the Browse button to locate it if you installed from a .zip file, for example). When you get to the Advanced Properties dialog, paste in the following after the program path:
-O - -q -t 1 http://www.example.com/cron.php
Adjust the rest of the options as described above and test it.
Using curl with cmd.exe in Windows 7 (or Vista) with Task Scheduler
- Start Computer Management (Windows Key, right-click Computer, select Manage...)
- In right column, select Create Job...
- Fill in General tab.
- Under Triggers tab, select New..., then set the desired schedule, with repeat set in Advanced Options.
- Under Actions tab, select Start a program, the program is CMD.EXE. For the optional argument, enter /C "curl [link provided on the status report page]".
If you have already installed mysysgit, curl is already present and in the path.
Under Windows 7 (or Vista), using schtasks and curl
Assuming you have already installed mysysgit as described above...
Run cmd.exe as Administrator, then enter the command:
C:\Windows\system32>schtasks /create /sc HOURLY /tn DevCron /tr "cmd.exe 'curl - -silent --compressed http://[[hostname]]/cron.php?cron_key=VOYz8P63mnytd0mHVwFE 1jrXfRfNYU9KZiKB1Ou1Rh8'" /ru SYSTEM
where [[hostname]] is the TLDN to the document root, /tn is the task name desired (here it's DevCron).
The above command yields a job that will run every hour, indefinitely.
Using external webcron service
If anyone finds above methods hard to manage, an easier way to schedule repeatedly executed tasks is using webcron service (e. g. EasyCron). Just via a browser, you can set up a webcron and it will periodically trigger your script.