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?
-
possible duplicate of How to run a PHP file in a scheduled task (Windows Task Scheduler)MaxiWheat– MaxiWheat2014-03-27 15:43:40 +00:00Commented Mar 27, 2014 at 15:43
-
You can find your answer here - stackoverflow.com/questions/39805601/…Sagar Jain– Sagar Jain2016-10-01 11:28:55 +00:00Commented Oct 1, 2016 at 11:28
12 Answers
Locate the php.exe executable on your system and pass it the name of the script file using the -f parameter.
Example:
C:\Xampp\php\php.exe -f C:\Xampp\htdocs\my_script.php
Reference:
3 Comments
bat file but no successphp file getting deleted, may i know the reason ?Here's how did it.
Windows scheduler -> create a new task -> action tab -> Edit

1 Comment
C:\laragon\bin\php\VERSION_PHP\php.exeAt 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.
For example in the bat file executephp.bat, write this
c:\xampp\php\php.exe -f c:\xampp\htdocs\do_something.php
save that bat file that contains that line.
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.
For example if u save the file under C:\xampp\htdocs put that C:\xampp\htdocs in the start in.
Remember to invoke the script even when the user is not logged on.
Everything is set and it will execute without problem.
3 Comments
" ?You can use PHP Command Line to execute it rather then trying to load it through the browser.
Under the actions tab, create a new action and:
- Program/Script: Point to your PHP.exe file
- Add Arguments:
-f /path/to/php/file.php
Optionally you can make it start in the script's directory as well.
Comments
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.
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)
Hope this helps.
Comments
You dont need a .bat file just set the options in the task scheduler:

So here i've just pointed to the php.exe and then in the arguments the
-f fullpath2PHP file
The important bit is the Start in part - this should be the folder your php file (the one you want to run) sits in. so for example:
File location -f c:\inetpub\wwwroot\runthisplease\myFile.php
Start in c:\inetpub\wwwroot\runthisplease\
You can test this by creating a windows shortcut (but you cannot schedule a shortcut link)
If the answer given by Pekka does not work (C:\Xampp\php\php.exe -f C:\Xampp\htdocs\my_script.php), make sure that you have the correct PHP extensions enabled as well as the correct php.ini file being used for the PHP version you are using.
I ran into this issue recently and resolved it. I was using PHP v5.4 to run my script.php that was nested within the top level PHP folder (v5.3). When I ran the script.php, from within the v5.4 folder, it was using the v5.3 php.ini file with different extensions, which caused the script.php to fail.
To fix this, here is what I did within the Task Scheduler : Actions tab
Program Script:
"C:\Program Files (x86)\PHP\v5.4\php.exe"
Add Arguements:
-c "C:\Program Files (x86)\PHP\v5.4\php.ini" -f "C:\Xampp\htdocs\script.php"
Using the -c option, you can specify which php.ini file should be used (stackflow answer).
I verified which php was in use by following this stackflow answer.
In command line, type php -m to check which extensions are enabled.
Then, use php --ini to check which .ini file(s) is/are being read by PHP.
You may not be using the correct ini file for the PHP version you are using if you have multiple versions installed.
1 Comment
Start in (optional) field, doesn’t support them. WINDOWS TASK SCHEDULER: THE DIRECTORY NAME IS INVALID. (0X8007010B)To create a scheduler in Windows, you need to:
- Create
.batfile on your server or system; - Type the following command in your
.batfile:
“F:\xampp\php\php.exe” -f “F:/xampp/htdocs/sitefolder/test.php”; - Set the scheduler time and file in your task scheduler in Windows.
1 Comment
" or omitted at all