windows 自动安排和执行 PHP 脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2764032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:24:22  来源:igfitidea点击:

Schedule and execute a PHP script automatically

phpwindowsautomationscheduled-tasksscheduling

提问by chupinette

I have written a PHP script which generates an SQL file containing all tables in my database. What I want to do is execute this script daily or every n days. I have read about cron jobs but I am using Windows. How can I automate the script execution on the server?

我编写了一个 PHP 脚本,它生成一个包含数据库中所有表的 SQL 文件。我想要做的是每天或每 n 天执行一次这个脚本。我已阅读有关 cron 作业的信息,但我使用的是 Windows。如何在服务器上自动执行脚本?

采纳答案by dmp

You'll need to add a scheduled task to call the URL.

您需要添加一个计划任务来调用 URL。

First of all, read up here: MS KB- this is for Windows XP.

首先,请阅读此处: MS KB- 这是针对 Windows XP 的。

Second, you'll need some way to call the URL - i'd recommend using something like wget- this way you can call the URL and save the output to a file, so you can see what the debug output is. You can get hold of wget on this page.

其次,您需要某种方式来调用 URL - 我建议使用类似wget 的方法- 这样您就可以调用 URL 并将输出保存到文件中,这样您就可以看到调试输出是什么。您可以在此页面上获取 wget 。

Final step is, as Gabriel says, write a batch file to tie all this up, then away you go.

最后一步是,正如 Gabriel 所说,编写一个批处理文件将所有这些联系起来,然后你就走了。

e: wget is pretty simple to use, but if you have any issues, leave a comment and I'll help out.

e: wget 使用起来非常简单,但是如果您有任何问题,请发表评论,我会提供帮助。

ee: thinking about it, you don't even really need a batch file, and could just call wget directly..

ee:想想看,你甚至不需要一个批处理文件,直接调用 wget 就可以了..

回答by Gabriel

add a scheduled task to request the url. either using a batch file or a script file (WSH).

添加计划任务以请求url。使用批处理文件或脚本文件 (WSH)。

http://blog.netnerds.net/2007/01/vbscript-download-and-save-a-binary-file/

http://blog.netnerds.net/2007/01/vbscript-download-and-save-a-binary-file/

this script will allow you to download binary data from a web source. Modify it to work for you particular case. This vbs file can either be run directly or executed from within a script. Alternately you do not have to save the file using the script, you can just output the contents (WScript.Echo objXMLHTTP.ResponseBody) and utilize the CMD out to file argument:

此脚本将允许您从 Web 源下载二进制数据。修改它以适合您的特定情况。这个 vbs 文件可以直接运行,也可以从脚本中执行。或者,您不必使用脚本保存文件,您只需输出内容 (WScript.Echo objXMLHTTP.ResponseBody) 并使用 CMD out to file 参数:

cscript download.vbs > logfile.log

cscript 下载.vbs > 日志文件.log

save that bad boy in a .bat file somewhere useful and call it in the scheduler: http://lifehacker.com/153089/hack-attack-using-windows-scheduled-tasks

将那个坏男孩保存在一个有用的 .bat 文件中,并在调度程序中调用它:http: //lifehacker.com/153089/hack-attack-using-windows-scheduled-tasks

回答by DWalkercouk

Cron is not always available on many hosting accounts.

许多托管帐户并不总是提供 Cron。

But try this: http://www.phpjobscheduler.co.uk/its free, has a useful interface so you can see all the scheduled tasks and will run on any host that provides php and mysql.

但是试试这个:http: //www.phpjobscheduler.co.uk/它是免费的,有一个有用的界面,所以你可以看到所有的计划任务,并且可以在任何提供 php 和 mysql 的主机上运行。

回答by Kousha

You can use ATriggerscheduling service. A PHP libraryis also available to create scheduled tasks without overhead. Reporting, Analytics, Error Handling and more benefits.

您可以使用ATrigger调度服务。一个PHP库也可以不开销创建计划任务。报告、分析、错误处理和更多好处。

Disclaimer: I was among the ATrigger team. It's a freeware and I have not any commercial purpose.

免责声明:我是 ATrigger 团队中的一员。这是一个免费软件,我没有任何商业目的。

回答by mukund

Yes, You can schedule and execute your php script on windows to run automatically. In linux like os u will have cron but on windows u can schedule task using task scheduler.

是的,您可以在 Windows 上安排和执行您的 php 脚本以自动运行。在像 os 这样的 linux 中你会有 cron 但在 windows 上你可以使用任务调度程序来安排任务。

回答by Marc B

Windows doesn't have cron, but it does come with the 'at' command. It's not as flexible as cron, but it will allow you to schedule arbitrary tasks for execution from the command line.

Windows 没有 cron,但它带有 ' at' 命令。它不如 cron 灵活,但它允许您从命令行安排任意任务执行。