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

时间:2022-02-16 05:31:05

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:\程序文件\Apache软件基础\Apache2.2\htdocs\ web\ 4w_website\save.php"

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

开始:“C:\程序文件\Apache软件基金会\Apache2.2\htdocs\WEB\4w_website”

It just opens the PHP file in Notepad.

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

I gave the correct user name and pwd.

我给出了正确的用户名和pwd。

Please help me..

请帮我. .

7 个解决方案

#1


67  

The Run command should be

运行命令应该是

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 OFF
php.exe -f "C:\code\cust.php"

And put it in the Schedule Tasks like this:

把它放到像这样的日程任务中:

Run: C:\code\file.bat

运行:C:\ \ file.bat代码

Start in: C:\code\

开始:C:\ \代码

#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脚本,在大多数情况下脚本都等待在当前文件夹中运行。这意味着你必须设置文件夹的每个动作,使用字段“Start In”。

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[文件]"在任务中。

#5


2  

This is what I did:

这就是我所做的:

  1. PHP file

    PHP文件

    <?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 path变量中,这可以从我的计算机、属性、高级设置、环境变量、new中完成

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

    接下来,我创建了一个.bat文件,只需打开下面的记事本和键入代码,并将其保存为myfile.bat

    @ECHO OFF
    php -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.

如果它仍然不能工作,检查你的文件。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.

删除它。如果文件中的包含文件。确实需要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

运行命令应该是

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 OFF
php.exe -f "C:\code\cust.php"

And put it in the Schedule Tasks like this:

把它放到像这样的日程任务中:

Run: C:\code\file.bat

运行:C:\ \ file.bat代码

Start in: C:\code\

开始:C:\ \代码

#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脚本,在大多数情况下脚本都等待在当前文件夹中运行。这意味着你必须设置文件夹的每个动作,使用字段“Start In”。

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[文件]"在任务中。

#5


2  

This is what I did:

这就是我所做的:

  1. PHP file

    PHP文件

    <?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 path变量中,这可以从我的计算机、属性、高级设置、环境变量、new中完成

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

    接下来,我创建了一个.bat文件,只需打开下面的记事本和键入代码,并将其保存为myfile.bat

    @ECHO OFF
    php -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.

如果它仍然不能工作,检查你的文件。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.

删除它。如果文件中的包含文件。确实需要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等)编写后端脚本?