Configure Cron for Drupal on Windows Server 2003

 

 


Requirements
Tested on Windows Server 2003
Download wget for Windows
http://gnuwin32.sourceforge.net/packages/wget.htm
http://users.ugent.be/~bpuype/wget/ (compiled)
Drupal version 6.x
http://drupal.org/
 
Install wget

Unpack wget and place in C:\Windows\System32

 
Create php script
Create a file cronall.php and paste the code below in the file, you will be able to add more sites in the $addedSites array.

 <?php

$cronUrl = 'http://%s/cron.php';
$addedSites = array();
$addedSites [] = 'www.website1.com';
$addedSites [] = 'www.website2.com';

error_reporting(E_ALL);
$sites = array();

//default site
if(isset($addedSites) && is_array($addedSites)){
$sites = array_merge($sites, $addedSites);
}
foreach($sites as $site){
$cmd = 'wget --spider '.sprintf($cronUrl, $site);
echo 'Executing command: '.$cmd.'<br>';
exec($cmd);
}

?>

 
Schedule a Task
- Go to Start|All Programs|Accessories|System Tools|Scheduled Tasks
- Add Scheduled Task
- Browse to C:\Program Files\PHP and select php-cgi.exe
- Give a name to the task (drupal cron schedule)
- Select how often and at what time the task must be executed.
- Enter the Username and Password which is used to execute the schedule
- Select Open advanced properties for this task when i click Finish.
-
Change Run in "C\Program Files\PHP\php-cgi.exe" cronall.php
- Change Start in C:\<drupal directory with cronall.php>
- Run the schedule
 

 

 
Check the schedule
Go to Administer|Status Report in Drupal and check if the Cron maintenance tasks executed correctly.
 
Sources
http://drupal.org/node/246091