How to create CRON jobs (Scheduled Tasks) in WAMP

August 9, 2014   /   by Marco  / Categories :  Technology

What is WAMP?

WAMP is a Windows based web development platform that allows you to create web applications with Apache2, PHP and MySQL. It is basically a package that you run on your Windows OS and it will turn the device into a web server.

What is a CRON job?

Ok, so CRON jobs is something that you would find in Unix system. On a Windows based system it’s actually called Scheduled Tasks. I find Windows scheduled tasks to be much easier to setup than CRON jobs but they do exactly the same thing. They run a task in the background at a specified internal.

In this post I will only detail the steps required to create a scheduled task for a web application running on WAMP.

ADD folder Path for PHP.exe

Click Start

Right Click Computer – Properties

Click Advanced system settings

Windows 7 - System Properties

Click Environment variables

Windows 7 - Environment Variables

At the end of the line add:

C:\wamp\bin\php\php5.5.12

Check to make sure the php.exe file exists in that folder. You may have a different folder name depending on the version of php.

Make sure you include the semi quotation marks ;

To verify to make sure it worked just open up the command prompt and type

set

This will display all your variables and you should see the php folder listed. Something like this:

cmd set command.exe

BATCH FILE

Create a batch file (open up a text editor like notepad and make sure you save the file as cron.bat. If the filename is cron.bat.txt then this is not a batch file)

@echo off
REM -----
REM Created By Business Legions www.businesslegions.com/blog
REM Cron job in WAMP
php -f C:\wamp\www\abc.php

 

You can also download the attached example.

To run a specific page to trigger certain events use the following syntax

For executing a file:

php -f C:\wamp\www\abc.php

For downloading a file you will need to get the windows based version of wget.

http://sourceforge.net/projects/gnuwin32/postdownload?source=dlp

Install the software and then add the path:

C:\Program Files (x86)\GnuWin32\bin

To the environment variables – see above steps

For executing a website:

all you need to do is add the program script

“C:\Program Files (x86)\Google\Chrome\Application\chrome.exe”

 

CREATE SCHEDULED TASK

Click Start

Right Click on Computer and select Manage

Windows 7 - Manage

In System Tools, Expand Task Scheduler  and Click on Task Scheduler Library. Create a new task:

Windows 7 - Task Scheduler - General

Set the Trigger settings eg frequency.

 

Windows 7 - Task Scheduler - Trigger

Set the action. In this particular example browse to the cron.bat file.

Windows 7 - Task Scheduler - New Action

 

The conditions and settings tabs are pretty much optional. Click ok and then the task will run based on the frequency you set.

It should say running next to the task name.

Windows 7 - Task Scheduler - Running

 

That’s it. The cron job will now run.

SILENT BAT

UPDATE: If you don’t want to have the Command window popup you can run the batch file within a Visual Basic script. To do this follow these steps:

Create a new file called cron.vbs and put in the following text. Replace the C:\Scheduled Jobs\cron.bat with the location of your batch file.

Dim WinScriptHost
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "C:\Scheduled Jobs\cron.bat" & Chr(34), 0
Set WinScriptHost = Nothing

Then in the task scheduler for the Action, select the file cron.vbs instead of the cron.bat file. This will run the batch file silently.

Below is the cron.vbs file.

FEEDBACK
I hope this has helped some of you. If you need any further help then please let me know.
DO YOU LIKE WHAT YOU'VE READ?
Join our subscription list and receive our content right in your mailbox. If you like to receive some Great deals our Freebies then subscribe now!

Our Sponsors

  • Follow us:

OTHER ARTICLES YOU MAY LIKE


HOW TO INSTALL NPM NODE.JS IN VISUAL STUDIO CODE

HOW TO INSTALL NPM NODE.JS IN VISUAL STUDIO CODE

When I first ventured into the world of web development, I stumbled upon Node.js and NPM. As I dig deeper, I realized these two tools were essential for building modern applications. In this section, I’ll unpack what Node.js is, why NPM is crucial, and share some common use cases that highlight the power of these […]

read more
POWERFUL REFERRAL PROGRAM TOOL

POWERFUL REFERRAL PROGRAM TOOL

Businesses of all sizes are constantly seeking new and innovative ways to grow their customer base and increase brand awareness. With the rise of social media and the reliance on word-of-mouth marketing, referral programs have become an essential tool for companies looking to expand their reach. However, managing a successful referral program can be a […]

read more

Like our Page