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
Here's how did it.
Windows scheduler -> create a new task -> action tab -> Edit
In the properties for your task in the Task Scheduler, change the account for which your script is running under to the SYSTEM account.
Beaware! You should ONLY do this for scripts you fully trust - Doing this elevates the privileges to of the script to beyond administrator.
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.
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.
At 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.
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 run in part - this should be the folder your php sits in. so for example:
File location -f c:\inetpub\wwwroot\runthisplease\myFile.php Run in c:\inetpub\wwwroot\runthisplease\
You can test this by creating a windows shortcut (but you cannot schedule a shortcut link)