如何在WAMP/Windows环境中每天自动运行PHP脚本? [英] How can I run a PHP Script automatically Daily in WAMP / Windows Environment?

查看:54
本文介绍了如何在WAMP/Windows环境中每天自动运行PHP脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在每天的预定时间运行一个PHP脚本来更新数据库中的某些字段.我该怎么做?

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

我尝试使用Windows Scheduler,但未运行脚本,无法弄清错误.

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.

我的蝙蝠文件:

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

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

测试PHP脚本:

<?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);
?>

推荐答案

您可以使用Windows调度程序使用命令 php full \ link \ to \ php \ file.php 进行此操作,如果此方法不起作用在系统 PATH 变量中,可能未正确链接到 php.exe 文件的链接.因此,您可以尝试使用以下 C:\ wamp \ bin \ php \ php5.5.12 \ php.exe C:\ wamp \ www \ test.php .

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.

此外,您还可以使用 at cmd命令来设置计划任务,您可以阅读有关它的更多信息

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

解决方案:

PHP文件:

<?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文件:

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

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

双击BAT文件将创建一个newfile.txt.

Double Click BAT File will Create a newfile.txt.

这篇关于如何在WAMP/Windows环境中每天自动运行PHP脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆