简体   繁体   English

如何安排Windows上PHP脚本的执行

[英]How can I schedule the execution of a PHP script on Windows

For my reminder system app I need to send emails, one day before the event . 对于提醒系统应用,我需要在活动开始前一天发送电子邮件。 The database stores the reminders with date , time , user_id . 该数据库存储带有datetimeuser_id的提醒。 Is there any way I can schedule an email that automatically gets sent a day before the event occurs ? 有什么办法可以安排在事件发生前一天自动发送的电子邮件?

1) Create a batch file that will run the script 1)创建一个将运行脚本的批处理文件

Open up notepad, add this command, with your own attributes: 打开记事本,添加以下命令,并使用自己的属性:

"PATH_TO_PHP.EXE" -f "SCRIPT_TO_RUN.PHP"

So it may look like this: 因此可能看起来像这样:

"C:\Program Files (x86)\PHP\v5.3\php.exe" -f "C:\tasks\task.php")

Save this file as a .bat file (Batch file). 将此文件另存为.bat文件(批处理文件)。

(OK so creating a batch file isn't completely necessary but what if you wanted to expand on this task? Right?) (好的,因此完全不需要创建批处理文件,但是如果您想扩展此任务怎么办?对吗?)

2) Have task scheduler run the task 2)让任务计划程序运行任务

Open up Task Scheduler (You'll find it in Accessories > System Tools , or just search for 'taskschd.msc') 打开任务计划程序 (您可以在“ 附件”>“系统工具”中找到它,或仅搜索“ taskschd.msc”)

Create a task. 创建一个任务。

Give it a name, Create a trigger for the specified day. 给它起一个名字,为指定的日期创建一个触发器

Now go to the Actions tab, hit New and it should say 'Start a program' by default. 现在转到“操作”选项卡,单击“新建”,默认情况下应显示“启动程序”。

Browse to the batch file that you just made, click OK and you're done. 浏览到您刚刚制作的批处理文件,单击“确定”,就完成了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM