在 Windows 本地主机上的 PHP 脚本上运行 Cron 作业

2022-01-03 00:00:00 windows cron wamp localhost php

我有一个 php 脚本,想按计划运行它.我在 Windows 上使用本地 Web 服务器(WAMP 服务器)并且需要一种方法来运行 my_script.php 每 10 分钟.

I have a php script and want to run it on an schedule. I am using local web server on windows (WAMP server) and need a way to run my_script.php every 10 min.

如何在 Windows 本地主机上的 PHP 脚本上运行 cron 作业?

How to run a cron job on a PHP script, on localhost in windows?

推荐答案

最近我在 Windows 7 的 localhost(WAMP 服务器)上的 php 脚本上运行 cron 作业时遇到了一些问题,当时我正在接受长期测试从 www 那里获取一些链接.

recently I had sort of problems to run a cron job on a php script on localhost (WAMP server) in windows 7, when I was on a test to chronically fetch some links from www out there.

顺便说一下,我将与任何有相同想法的人分享这个.

By the way I am sharing this for anyone that is on the same thing.

您需要一个 shellscript 来长期运行,使用 Windows 任务计划程序.此外,您还需要一个批处理脚本 (script.bat) 来调用 php.exe 并运行您的 php 脚本(此处称为 my_process.php)

You will need a shellscript to run chronically, using Windows Task Scheduler. Also you will need a batch script (script.bat) to call the php.exe and run your php script (here called as my_process.php)

shellscript.vbs

Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "C:path	oscriptscript.bat" & Chr(34), 0
Set WinScriptHost = Nothing

script.bat

"C:wampinphpphp5.4.12php.exe" -f "C:wampwwwwebsitemy_process.php"

现在,我们已准备好设置 Windows 任务计划程序 以在所需的时间间隔运行 shellscript.vbs:

Now, we are ready to set the Windows Task Scheduler to run shellscript.vbs at the required time interval:

  1. 从窗口开始菜单中打开任务计划
  2. 转到操作菜单并点击创建任务...
  3. 在常规标签中,根据需要填写名称和描述字段
  4. 在触发器标签中,点击新建按钮.
  5. 从开始任务下拉菜单中,选择按计划并选择每天
  6. 从高级设置部分,根据需要选择重复任务时间并将持续时间设置为无限期.
  7. 在操作标签上,从操作下拉菜单中选择启动程序.
  8. 在Programscript框中,输入shellscript.vbs的路径,如C:path oshellscript.vbs.
  9. 将添加参数(可选)部分留空.
  10. 在Start in (optional)框中,输入shellscript.vbs的父目录,如C:path o.
  11. 对本教程点赞 :) 玩得开心.
  1. Open Task Scheduler from windows Start menu
  2. Go to Action menu and hit Create Task...
  3. in General tab, fill the Name and Description fields as you want
  4. in Triggers tab, hit New button.
  5. from Begin the Task dropdown, select On a schedule and choose Daily
  6. from Advanced settings section, select Repeat task every as you want and set for a duration on Indefinitely.
  7. on Actions tab, from Action dropdown, select Start a program.
  8. on the Programscript box, enter path to shellscript.vbs like C:path oshellscript.vbs.
  9. leave Add argumentts (optional) section empty.
  10. in Start in (optional) box, enter parent directory of shellscript.vbs like C:path o.
  11. Hit upvote on this tutorial :) Have fun.

相关文章