问题
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);
?>
回答1:
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.
回答2:
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.
回答3:
You, also, may have to look at one of the following applications:
- http://cronw.sourceforge.net/ (free)
- http://www.z-cron.com/
- http://www.visualcron.com/
Or use this Google search (Windows cron)
来源:https://stackoverflow.com/questions/33932617/how-can-i-run-a-php-script-automatically-daily-in-wamp-windows-environment