How to run a PHP file in a scheduled task (Windows Task Scheduler)

The Run command should be

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

From the command line help of php.exe:

-f         Parse and execute <file>.

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\


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\

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.


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,