CronTab in Windows - How to Configure Scheduler to Handle Chronograph Tables

Windows operating systems and servers (unlike Linux and Unix-based systems) do not have the ability to run crontab events. This can become a problem is you are trying to configure and run a server set-up that is time dependent.

The Use of CronTab

Crontab is used to trigger routine events that enable web applications to do 'house cleaning' in the form of:
- Sending scheduled email messages
- Performing backup
- Synchronising data between one or multiple systems
- Releasing memory and freeing resources

as well as almost any other process that can be carried out manually.

Problem

In desktop Windows, the Schedule accessory can be used to run routine processes like clean-up, but these are mainly executable files/programs and web applications do not always have Windows executables that can be run.

Solution

A quick thought might be to invoke an installed Windows application and make it call the desired URL, but this is not reliable. The proper solution is based on the use of a core web application that handles CGI processes on the server. If PHP or Perl is installed, the cronTab trigger file (URL) can be called as an arguement of Perl or PHP.

Implementation/How to:

  • Create a batch file and add the following lines into it (PHP example) - CRON.BAT
    C:\PHP\PHP cron.php
    Where the first portion is referring to where the PHP application server executable file is and cron.php is the file that you want the PHP application to run. Depending on your director structure, you can adjust the paths accordingly so that the system can find the components (Specifying the paths in your PATH settings can help you locate the PHP application without a directory structure)
  • Create a Windows schedule event and make it call CRON.BAT as frequently as you would like the cron to be run and there you have your CRONTAB implemented in Windows.
  • Every time that crontab is run, Windows will open a DOS window and close it once the process is finished - see below

*NB: There may be an error displayed in the DOS window that opens every time the schedule runs the CronTab, you may choose to ignore it if you check your web application and confirm that the scheduled crontab is being performed with no problems despite the windows error

Windows CronTab Batch file error view

If you need help implementing this, feel free to contact us for complimentary assistance or if you have a large project, we will require payment

 

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Executing multiple cronjobs on a Windows Server

I have a problem that I can't seem to figure out. I have two update files,
c:\update\update1.php, c:\update\update2.php which I both want to schedule
to run on my Windows oriented webserver. How can I do this???

Calling multiple crontab/scheduler commands

You could either create two different cron.bat files each calling a different command (update1.php, u[date2.php), or more simply, you can add both commands in the batch file. In the second (my preferred case), the cron.bat file will look something like this:

# running first scheduled PHP command
C:\PHP\PHP update1.php

# running second scheduled PHP command
C:\PHP\PHP update2.php

The above are solutions you can use if you want to restrict the solution to the Windows server side of things. You can also identify and create one cronTab PHP file that can call a whole lot of other commands and files that will need scheduled housekeeping calls.

You can accomplish this by creating a single file, and within it including calls to the other files that have functions to be run, or just calling functions that are globally available.

Example:
Inside a file called cron.php or update.php

<?php include_once './thefilepath/update1.php'
include_once './otherfilepath/update2.php'
// Call specific functions that may not already be called within the above update files
first_update_function (somevariables);
other_update_function (othervariables);
php>

Valid XHTML 1.0 Strict
This site is accepts Oped ID authentication for login
This Website is Built Using Semantic Markup and Cascading Style Sheets (CSS)
Some usage rights are reserved, please contact us for approval before using it