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