How do I run a PHP script using windows schedule task?

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.


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.


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:

  • Introduction to using PHP on the command line
  • PHP command line options

Here's how did it.

Windows scheduler -> create a new task -> action tab -> Edit

enter image description here