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

帅比萌擦擦* 提交于 2021-01-28 03:41:36

问题


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:

  1. http://cronw.sourceforge.net/   (free)
  2. http://www.z-cron.com/
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!