2

I have a server 2008 64 bit machine with php5 via fastcgi installed. I want to run a .php script every day at 3 AM. I set up a task and "Last Run Result" says "%1 is not a valid Win32 application"

The event properties describe more failure:

"Task Scheduler failed to launch action "D:\InetPub\tools\something\build.php" in instance "{88cc01f4-9554-4b8f-9836-34d806337d7f}" of task "\Something". Additional Data: Error Value: 2147942593."

Task Category: Action failed to start

Is it possible to run scripts using the task scheduler? If not, how should I go about automating the execution of a php script?

Thanks

MadHatter
  • 78,442
  • 20
  • 178
  • 229

2 Answers2

2

I mostly run php on *nix machines so not sure about this.

Normally php scripts are run by the web-server when someone requests a page with some php in it.

In your Server 2008 set-up your default action for .php may be set to another action (e.g. 'open file in editor') rather than 'run script using php.exe'

You have to call up the php interpreter and use your actual script as a command line parameter.

Something like

php.exe d:\InetPub\tools\something\build.php

You may also be able to achieve the same effect by associating .php files with the correct program

Loopo
  • 415
  • 1
  • 9
  • 20
0

It is definitely possible to schedule php scripts to run as scheduled tasks and it is possible to pass arguments to the php script similar but not the same as you pass them to a PHP script via a browser. You will not access passed parameters via $_REQUEST. You will use $_SERVER['argv'] instead and parse yourself.

There are differences in the runtime environments so if your script is designed to be run both from a browser and also from the command line, you can use

if(PHP_SAPI=='cli'){
 //this is command line interface
}else{
 // this is a different interface
}
  • Make sure that windows knows the full path to php.exe either by explicitly specifying it or by setting the current directory in the task setup panel.
  • Pass php.exe the full path to the script that you want it to run
  • enclose the script name on quotation marks (") if there are embedded spaces in the path
  • enclose any argument that you pass in quotation marks if it has embedded spaces.
Ted Cohen
  • 136
  • 3