如何在计划任务中运行PHP文件(Windows任务计划程序)

时间:2022-04-25 05:13:41

How can I create a scheduled task to run a PHP file?
Yes, I filled out everything in the scheduled task, but it still doesn't work.

如何创建计划任务来运行PHP文件?是的,我填写了计划任务中的所有内容,但仍然无效。

Run: "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\WEB\4w_website\save.php"

运行:“C:\ Program Files \ Apache Software Foundation \ Apache2.2 \ htdocs \ WEB \ 4w_website \ save.php”

Start in: "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\WEB\4w_website"

开始于:“C:\ Program Files \ Apache Software Foundation \ Apache2.2 \ htdocs \ WEB \ 4w_website”

It just opens the PHP file in Notepad.

它只是在记事本中打开PHP文件。

I gave the correct user name and pwd.

我给了正确的用户名和密码。

Please help me..

请帮我..

7 个解决方案

#1


67  

The Run command should be

Run命令应该是

C:\Path\to\php.exe -f "C:\Path\to\file.php"

From the command line help of php.exe:

从php.exe的命令行帮助:

-f         Parse and execute <file>.

#2


14  

I just wrote a .bat file that does the work file.bat

我刚写了一个.bat文件来完成工作文件.bat

@ECHO OFFphp.exe -f "C:\code\cust.php"

And put it in the Schedule Tasks like this:

并将它放在Schedule Tasks中,如下所示:

Run: C:\code\file.bat

Start in: C:\code\

开始于:C:\ code \

#3


6  

If you running php scripts, in most of cases script awaiting to be runned in current folder.That mean you must set up folder each your action, use field "Start In".

如果您运行php脚本,在大多数情况下等待在当前文件夹中运行的脚本。这意味着您必须为每个操作设置文件夹,请使用“开始”字段。

Example:

Run: C:\php\php.exe Arguments: -f C:\web\myscript.php

Do not forget:

不要忘记:

 Start in: C:\web\

#4


5  

Sounds like you don't have PHP files associated with the EXE.

听起来你没有与EXE相关的PHP文件。

You can do this My Computer > Tools > Folder Options > File Types. If nothing else, this can also help you verify your settings for them.

您可以执行以下操作:我的电脑>工具>文件夹选项>文件类型。如果没有别的,这也可以帮助您验证它们的设置。

Otherwise, you can specify "C:\path\to\php.exe [file]" in the task.

否则,您可以在任务中指定“C:\ path \ to \ php.exe [file]”。

#5


2  

This is what I did:

这就是我做的:

  1. PHP file

    <?php my code goes here ?>

    *Note if you are using HTTP API/CURL in CLI use dl("php_curl.dll");

    *请注意,如果您在CLI中使用HTTP API / CURL,请使用dl(“php_curl.dll”);

    this loads curl into cli

    这会将卷曲加载到cli中

  2. Now I added PHP to windows path variable, this can be done from My computer, properties, advanced settings, environment variables, new

    现在我将PHP添加到windows路径变量,这可以从我的计算机,属性,高级设置,环境变量,新增

  3. Next I created a .bat file, simply open a notepad & type code below and save as myfile.bat

    接下来我创建了一个.bat文件,只需在下面打开一个记事本和类型代码并另存为myfile.bat

    @ECHO OFFphp -f d:\wamp\www\V3\task.php

    This site might help you on .bat file syntax.

    此网站可能会帮助您处理.bat文件语法。

  4. Now create a new scheduled task on windows & call the above .bat file as source,

    现在在Windows上创建一个新的计划任务并调用上面的.bat文件作为源,

#6


2  

For those people that can't able to make @Tomalak's answer work:

Check if there are spaces () in your directory. If it does, you need to enclose them with ".

检查目录中是否有空格()。如果是,你需要用“。”将它们括起来。

"C:\Path\to php file\php.exe" -f "C:\Path\to php file\file.php"

And if it still did not work, check your file.php if there are included files in it.

如果它仍然不起作用,检查你的file.php是否包含文件。

include("file2.php"); /* OR */include_once("file2.php");

Remove it. And if the included file in your file.php is really needed, try to move the code/script from that included file to your main file.

去掉它。如果确实需要file.php中包含的文件,请尝试将代码/脚本从包含的文件移动到主文件中。

#7


-2  

I think, you must execute your PHP script via URL.you can write batch script for execute URL.Why you don't write backend script in other language such as batch script, vbscript or etc.

我想,你必须通过URL执行你的PHP脚本。你可以为执行URL编写批处理脚本。为什么你不用其他语言编写后端脚本,如批处理脚本,vbscript等。

#1


67  

The Run command should be

Run命令应该是

C:\Path\to\php.exe -f "C:\Path\to\file.php"

From the command line help of php.exe:

从php.exe的命令行帮助:

-f         Parse and execute <file>.

#2


14  

I just wrote a .bat file that does the work file.bat

我刚写了一个.bat文件来完成工作文件.bat

@ECHO OFFphp.exe -f "C:\code\cust.php"

And put it in the Schedule Tasks like this:

并将它放在Schedule Tasks中,如下所示:

Run: C:\code\file.bat

Start in: C:\code\

开始于:C:\ code \

#3


6  

If you running php scripts, in most of cases script awaiting to be runned in current folder.That mean you must set up folder each your action, use field "Start In".

如果您运行php脚本,在大多数情况下等待在当前文件夹中运行的脚本。这意味着您必须为每个操作设置文件夹,请使用“开始”字段。

Example:

Run: C:\php\php.exe Arguments: -f C:\web\myscript.php

Do not forget:

不要忘记:

 Start in: C:\web\

#4


5  

Sounds like you don't have PHP files associated with the EXE.

听起来你没有与EXE相关的PHP文件。

You can do this My Computer > Tools > Folder Options > File Types. If nothing else, this can also help you verify your settings for them.

您可以执行以下操作:我的电脑>工具>文件夹选项>文件类型。如果没有别的,这也可以帮助您验证它们的设置。

Otherwise, you can specify "C:\path\to\php.exe [file]" in the task.

否则,您可以在任务中指定“C:\ path \ to \ php.exe [file]”。

#5


2  

This is what I did:

这就是我做的:

  1. PHP file

    <?php my code goes here ?>

    *Note if you are using HTTP API/CURL in CLI use dl("php_curl.dll");

    *请注意,如果您在CLI中使用HTTP API / CURL,请使用dl(“php_curl.dll”);

    this loads curl into cli

    这会将卷曲加载到cli中

  2. Now I added PHP to windows path variable, this can be done from My computer, properties, advanced settings, environment variables, new

    现在我将PHP添加到windows路径变量,这可以从我的计算机,属性,高级设置,环境变量,新增

  3. Next I created a .bat file, simply open a notepad & type code below and save as myfile.bat

    接下来我创建了一个.bat文件,只需在下面打开一个记事本和类型代码并另存为myfile.bat

    @ECHO OFFphp -f d:\wamp\www\V3\task.php

    This site might help you on .bat file syntax.

    此网站可能会帮助您处理.bat文件语法。

  4. Now create a new scheduled task on windows & call the above .bat file as source,

    现在在Windows上创建一个新的计划任务并调用上面的.bat文件作为源,

#6


2  

For those people that can't able to make @Tomalak's answer work:

Check if there are spaces () in your directory. If it does, you need to enclose them with ".

检查目录中是否有空格()。如果是,你需要用“。”将它们括起来。

"C:\Path\to php file\php.exe" -f "C:\Path\to php file\file.php"

And if it still did not work, check your file.php if there are included files in it.

如果它仍然不起作用,检查你的file.php是否包含文件。

include("file2.php"); /* OR */include_once("file2.php");

Remove it. And if the included file in your file.php is really needed, try to move the code/script from that included file to your main file.

去掉它。如果确实需要file.php中包含的文件,请尝试将代码/脚本从包含的文件移动到主文件中。

#7


-2  

I think, you must execute your PHP script via URL.you can write batch script for execute URL.Why you don't write backend script in other language such as batch script, vbscript or etc.

我想,你必须通过URL执行你的PHP脚本。你可以为执行URL编写批处理脚本。为什么你不用其他语言编写后端脚本,如批处理脚本,vbscript等。