How to run a PHP file in a scheduled task (Windows

2019-01-01 15:18发布

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.

Run: "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"

It just opens the PHP file in Notepad.

I gave the correct user name and pwd.

Please help me..

7条回答
墨雨无痕
2楼-- · 2019-01-01 15:35

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

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

And put it in the Schedule Tasks like this:

Run: C:\code\file.bat

Start in: C:\code\

查看更多
琉璃瓶的回忆
3楼-- · 2019-01-01 15:35

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");

    this loads curl into cli

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

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

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

    This site might help you on .bat file syntax.

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

查看更多
低头抚发
4楼-- · 2019-01-01 15:41

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

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.

查看更多
零度萤火
5楼-- · 2019-01-01 15:43

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.

查看更多
旧时光的记忆
6楼-- · 2019-01-01 15:52

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".

Example:

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

Do not forget:

 Start in: C:\web\
查看更多
冷夜・残月
7楼-- · 2019-01-01 15:56

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.

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.

查看更多
登录 后发表回答