DonOfDen
DonOfDen

Reputation: 4088

How can I run a PHP Script automatically Daily in WAMP / Windows Environment?

I need to run a PHP script at the scheduled time daily to update some fields in database. How I can do this?

I tried with windows scheduler and it not running the script I cant figure our the error.

Is there any tutorial or steps which helps to understand the working, so as to configure.

My Bat File:

H:\wamp\bin\php\php5.5.12\php.exe H:\wamp\www\file\file.php

Test PHP Script:

<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
?>

Upvotes: 2

Views: 3764

Answers (3)

SaidbakR
SaidbakR

Reputation: 13544

You, also, may have to look at one of the following applications:

  1. http://cronw.sourceforge.net/   (free)
  2. http://www.z-cron.com/
  3. http://www.visualcron.com/

Or use this Google search (Windows cron)

Upvotes: 0

Gvidas
Gvidas

Reputation: 1964

You can do this with windows scheduler with command php full\link\to\php\file.php, if this not working probably link to php.exe file is not properly linked in systems PATH variable. So you can try then something like this C:\wamp\bin\php\php5.5.12\php.exe C:\wamp\www\test.php.

Also you can use at cmd command to set up schedule task, you can read more about it here

Solution:

PHP File:

<?php
$myfile = fopen("H:\\wamp\\www\\file\\newfile.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
?>

BAT File:

H:\wamp\bin\php\php5.5.12\php.exe H:\wamp\www\file\file.php

Double Click BAT File will Create a newfile.txt.

Upvotes: 2

Sivaprakash
Sivaprakash

Reputation: 473

Create a .bat file with following code:

@ECHO OFF
path\to\php.exe -f "path\to\your_file.php"

Now schedule the task in Task Scheduler using the created .bat file.

Upvotes: 1

Related Questions