Web Toastie


Social Media and SEO Blog of a Search Marketing Consultant

21 Feb, 2009

Windows Alternative to Cron Jobs

You are here: Home » Geeky » Windows Alternative to Cron Jobs

I’m currently mid-way through the development of the football predictions website I am completing for my final year project, and came across a problem that proved quite difficult to solve. In order to help people who may find themselves in a similar situation, I decided to post the solution.

To ensure that users could not predict scores for fixtures that had already kicked off, I had to make a PHP script that would check the current time against the kickoff time, and lock the fixture if it was 15 minutes prior to the start of the match.

After coding the PHP I realised that the file would only be useful if it was constantly being ran in order to check the current time. Searching Google proved difficult as the majority of the results were in relation to Linux, and “Cron jobs” (I still don’t actually know what they are, but anyway…), until I came across this forum post.

It turns out that Windows Task Scheduler can be used to execute files based on certain criteria, so here is a quick step-by-step for anybody wondering how to solve a problem like this.

  • 1 – Created the PHP file that would lock the fixtures based on a certain time.
  • 2 – Realised that I didn’t want a new Firefox window opening every time the file was executed, so identified the following line of code to run in Command Prompt:
    c:\php\php.exe c:\Apache\htdocs\project\cms_lock_predictions.php.
  • 3 – Placed the aforementioned code in a Notepad file, then saved that file with a .BAT extension (to make it become an executable file).
  • Used Windows Task Scheduler (Start > All Programs > Accessories > System Tools [in Vista]) to create a new task that would run the .BAT executable every 15 minutes in order to update my project.

And that is all that is needed – job done.

Obviously this is only a solution for a website hosted on a local machine (or one being used for testing purposes – such as mine), so I’m not sure exactly what is needed for this to work on a live server.

Hope this helps.

No related posts.

Enjoyed this post? Enter your email address here to receive updates whenever a new article is published on Web Toastie:

Delivered by FeedBurner

2 Responses to "Windows Alternative to Cron Jobs"

1 | Chris Casey

February 21st, 2009 at 1:59 am

Avatar

Wow yeah that really helped cheers

2 | Owen

May 20th, 2009 at 11:35 am

Avatar

Be sure to release this, my betfair account is empty ;)

Comment Form


About

Web Toasite is the social media and SEO blog of Kieron Hughes - a Manchester search marketing consultant with experience running SEO campaigns in a variety of sectors online.

Kieron blogs about SEO industry news, web development and advances in social media. If you wish to contact Kieron you can do so through the online contact form, or connect via the following social networking websites.