在Windows上的localhost上的PHP脚本上运行Cron作业 [英] Run Cron Job on PHP Script, on localhost in Windows
问题描述
我有一个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脚本上的localhost上运行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.
您需要使用 Windows任务计划程序长期运行 shellscript 。此外,您还需要一个批处理脚本( 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\to\script\script.bat" & Chr(34), 0
Set WinScriptHost = Nothing
script.bat
"C:\wamp\bin\php\php5.4.12\php.exe" -f "C:\wamp\www\website\my_process.php"
,我们准备设置 Windows任务计划程序以所需的时间间隔运行 shellscript.vbs :
Now, we are ready to set the Windows Task Scheduler to run shellscript.vbs at the required time interval:
- 从Windows 开始菜单中打开任务计划程序。
- 转到操作菜单并点击常规标签中的创建任务...
- ,填写名称< 标签中,按新按钮。
- 从开始任务下拉菜单中选择按时间表,然后选择每日
- 高级设置部分,根据需要选择每次重复任务,并在无限期上设置 下拉菜单中选择启动程序。
- 。
li>在 Program \script 框中输入shellscript.vbs的路径,例如 C:\path\to\shellscript.vbs 。 $在开始(可选)框中输入父元素。 目录下的shellscript.vbs如
C:\path\to\
。 - 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 Program\script box, enter path to shellscript.vbs like C:\path\to\shellscript.vbs.
- leave Add argumentts (optional) section empty.
- in Start in (optional) box, enter parent directory of shellscript.vbs like
C:\path\to\
. - Hit upvote on this tutorial :) Have fun.
这篇关于在Windows上的localhost上的PHP脚本上运行Cron作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!