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

Run Cron Job on PHP Script, on localhost in Windows(在 Windows 本地主机上的 PHP 脚本上运行 Cron 作业)
本文介绍了在 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:

  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.

这篇关于在 Windows 本地主机上的 PHP 脚本上运行 Cron 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)