如何使用Windows计划任务运行PHP脚本?

时间:2021-05-29 02:28:28

I have installed localhost/server in my machine and I need to run a php script using windows schedule task. how do I add path in "Actions" tab in schedule task / cofigure the script to run for particular period?

我在我的机器上安装了localhost / server,我需要使用windows schedule任务运行php脚本。如何在计划任务的“操作”选项卡中添加路径/配置脚本以运行特定时间段?

9 个解决方案

#1


44  

Locate the php.exe executable on your system and pass it the name of the script file using the -f parameter.

在系统上找到php.exe可执行文件,并使用-f参数将其传递给脚本文件的名称。

Example:

例:

C:\Xampp\php\php.exe -f C:\Xampp\htdocs\my_script.php

Reference:

参考:

#2


10  

Here's how did it.

这是怎么做的。

Windows scheduler -> create a new task -> action tab -> Edit

Windows调度程序 - >创建新任务 - >操作选项卡 - >编辑

如何使用Windows计划任务运行PHP脚本?

#3


9  

You can use PHP Command Line to execute it rather then trying to load it through the browser.

您可以使用PHP命令行执行它,而不是尝试通过浏览器加载它。

Under the actions tab, create a new action and:

在操作选项卡下,创建一个新操作并:

  • Program/Script: Point to your PHP.exe file
  • 程序/脚本:指向您的PHP.exe文件
  • Add Arguments: -f /path/to/php/file.php
  • 添加参数:-f /path/to/php/file.php

Optionally you can make it start in the script's directory as well.

您也可以选择在脚本目录中启动它。

#4


8  

At least I tried out some suggestions but it doesn't work so I tried this.

至少我尝试了一些建议,但它没有用,所以我尝试了这个。

Use a bat file and schedule to execute that bat file.

使用bat文件并安排执行该bat文件。

For example in the bat file executephp.bat, write this

例如,在bat文件executephp.bat中,写下这个

c:\xampp\php\php.exe -f c:\xampp\htdocs\do_something.php

c:\ xampp \ php \ php.exe -f c:\ xampp \ htdocs \ do_something.php

save that bat file that contains that line.

保存包含该行的bat文件。

Go to windows scheduler and create a new task and in action tab, browse to point that executephp.bat and for start in -> direct to the directory u have that executephp.bat.

转到Windows调度程序并创建一个新任务并在操作选项卡中,浏览指向executephp.bat并在 - >中直接启动到具有该executephp.bat的目录。

For example if u save the file under C:\xampp\htdocs put that C:\xampp\htdocs in the start in.

例如,如果您将文件保存在C:\ xampp \ htdocs下,则将C:\ xampp \ htdocs放在开头。

Remember to invoke the script even when the user is not logged on.

即使用户未登录,也要记得调用脚本。

Everything is set and it will execute without problem.

一切都已设定,它将毫无问题地执行。

#5


3  

Here's how I did it.

这是我如何做到的。

In the Run box: c:\location_of_my_php_installation\php.exe -f c:\location_of_my_php_file\php_file.php

在运行框中:C:\ location_of_my_php_installation \的php.exe -f C:\ location_of_my_php_file \ php_file.php

In the Start in box: c:\location_of_my_php_installation\php.exe

在“开始”框中:c:\ location_of_my_php_installation \ php.exe

#6


2  

I just wanted to leave what i had to do to get this working for server 2012. Which was what has previously been said but with added quotes and using the 'Add arguments' box. So in Task Scheduler->Actions->Edit Action.

我只是想留下我必须做的事情来使这个服务器在2012服务器上工作。这是之前已经说过但添加了引号并使用“添加参数”框。所以在Task Scheduler-> Actions-> Edit Action中。

Program/script: "C:\xampp\php\php.exe"
Add arguments: -f "<full path and filename>"
Start in: <Path to file>

(I had to use 'start in' as i referred to class's within the script)

(我不得不使用'start in',因为我在脚本中引用了类)

Hope this helps.

希望这可以帮助。

#7


1  

you can directly call your local host url by using

您可以使用直接调用本地主机URL

explorer "http://localhost/yourFile.php"

#8


0  

In the properties for your task in the Task Scheduler, change the account for which your script is running under to the SYSTEM account.

在任务计划程序中的任务属性中,将运行脚本的帐户更改为SYSTEM帐户。

Beaware! You should ONLY do this for scripts you fully trust - Doing this elevates the privileges to of the script to beyond administrator.

意识到!您应该只对您完全信任的脚本执行此操作 - 这样做会将脚本的权限提升到管理员之外。

#9


-1  

To create scheduler in windows, you need to

要在Windows中创建调度程序,您需要

  1. create .bat file on your server or system;
  2. 在您的服务器或系统上创建.bat文件;
  3. type the following command in your.bat file. “F:\xampp\php\php.exe” -f “F:/xampp/htdocs/sitefolder/test.php”;
  4. 在your.bat文件中键入以下命令。 “F:\ xampp \ php \ php.exe”-f“F:/xampp/htdocs/sitefolder/test.php”;
  5. set the scheduler time and file in your task scheduler in windows.
  6. 在Windows中的任务计划程序中设置调度程序时间和文件。

#1


44  

Locate the php.exe executable on your system and pass it the name of the script file using the -f parameter.

在系统上找到php.exe可执行文件,并使用-f参数将其传递给脚本文件的名称。

Example:

例:

C:\Xampp\php\php.exe -f C:\Xampp\htdocs\my_script.php

Reference:

参考:

#2


10  

Here's how did it.

这是怎么做的。

Windows scheduler -> create a new task -> action tab -> Edit

Windows调度程序 - >创建新任务 - >操作选项卡 - >编辑

如何使用Windows计划任务运行PHP脚本?

#3


9  

You can use PHP Command Line to execute it rather then trying to load it through the browser.

您可以使用PHP命令行执行它,而不是尝试通过浏览器加载它。

Under the actions tab, create a new action and:

在操作选项卡下,创建一个新操作并:

  • Program/Script: Point to your PHP.exe file
  • 程序/脚本:指向您的PHP.exe文件
  • Add Arguments: -f /path/to/php/file.php
  • 添加参数:-f /path/to/php/file.php

Optionally you can make it start in the script's directory as well.

您也可以选择在脚本目录中启动它。

#4


8  

At least I tried out some suggestions but it doesn't work so I tried this.

至少我尝试了一些建议,但它没有用,所以我尝试了这个。

Use a bat file and schedule to execute that bat file.

使用bat文件并安排执行该bat文件。

For example in the bat file executephp.bat, write this

例如,在bat文件executephp.bat中,写下这个

c:\xampp\php\php.exe -f c:\xampp\htdocs\do_something.php

c:\ xampp \ php \ php.exe -f c:\ xampp \ htdocs \ do_something.php

save that bat file that contains that line.

保存包含该行的bat文件。

Go to windows scheduler and create a new task and in action tab, browse to point that executephp.bat and for start in -> direct to the directory u have that executephp.bat.

转到Windows调度程序并创建一个新任务并在操作选项卡中,浏览指向executephp.bat并在 - >中直接启动到具有该executephp.bat的目录。

For example if u save the file under C:\xampp\htdocs put that C:\xampp\htdocs in the start in.

例如,如果您将文件保存在C:\ xampp \ htdocs下,则将C:\ xampp \ htdocs放在开头。

Remember to invoke the script even when the user is not logged on.

即使用户未登录,也要记得调用脚本。

Everything is set and it will execute without problem.

一切都已设定,它将毫无问题地执行。

#5


3  

Here's how I did it.

这是我如何做到的。

In the Run box: c:\location_of_my_php_installation\php.exe -f c:\location_of_my_php_file\php_file.php

在运行框中:C:\ location_of_my_php_installation \的php.exe -f C:\ location_of_my_php_file \ php_file.php

In the Start in box: c:\location_of_my_php_installation\php.exe

在“开始”框中:c:\ location_of_my_php_installation \ php.exe

#6


2  

I just wanted to leave what i had to do to get this working for server 2012. Which was what has previously been said but with added quotes and using the 'Add arguments' box. So in Task Scheduler->Actions->Edit Action.

我只是想留下我必须做的事情来使这个服务器在2012服务器上工作。这是之前已经说过但添加了引号并使用“添加参数”框。所以在Task Scheduler-> Actions-> Edit Action中。

Program/script: "C:\xampp\php\php.exe"
Add arguments: -f "<full path and filename>"
Start in: <Path to file>

(I had to use 'start in' as i referred to class's within the script)

(我不得不使用'start in',因为我在脚本中引用了类)

Hope this helps.

希望这可以帮助。

#7


1  

you can directly call your local host url by using

您可以使用直接调用本地主机URL

explorer "http://localhost/yourFile.php"

#8


0  

In the properties for your task in the Task Scheduler, change the account for which your script is running under to the SYSTEM account.

在任务计划程序中的任务属性中,将运行脚本的帐户更改为SYSTEM帐户。

Beaware! You should ONLY do this for scripts you fully trust - Doing this elevates the privileges to of the script to beyond administrator.

意识到!您应该只对您完全信任的脚本执行此操作 - 这样做会将脚本的权限提升到管理员之外。

#9


-1  

To create scheduler in windows, you need to

要在Windows中创建调度程序,您需要

  1. create .bat file on your server or system;
  2. 在您的服务器或系统上创建.bat文件;
  3. type the following command in your.bat file. “F:\xampp\php\php.exe” -f “F:/xampp/htdocs/sitefolder/test.php”;
  4. 在your.bat文件中键入以下命令。 “F:\ xampp \ php \ php.exe”-f“F:/xampp/htdocs/sitefolder/test.php”;
  5. set the scheduler time and file in your task scheduler in windows.
  6. 在Windows中的任务计划程序中设置调度程序时间和文件。