Search code examples
phpbatch-filescheduled-tasksundefinedsuperglobals

Undefined $_SCRIPT variables when executing php from a scheduled task


Thank you for your time in advance.

I have a php script that is supposed to run once daily. We set up a scheduled task on the client's server and it executes a batch file that essentially calls the following:

php-cgi.exe -d short_open_tag=On ".\my_script.php"

If I navigate directly to my_script.php via the browser everything works fine. When I execute the batch script from either the command line or via a scheduled task I'm given multiple errors.

  1. The last run result of the task scheduler is always "(0xFFFFFFFF)".
  2. The first error from the command line is "Notice: Undefined index: DOCUMENT_ROOT".
  3. The second error from the command line is "Notice: Undefined index: SCRIPT_NAME".

Lines giving errors:

$document_root = $_SERVER[ 'DOCUMENT_ROOT' ];
$_SERVER[ 'FULL_URL' ] .= $_SERVER[ 'SCRIPT_NAME' ];

If I var_dump() the $_SERVER variable I see both the DOCUMENT_ROOT and SCRIPT_NAME are there and populated properly. I have the scheduled task running with highest privileges under the SYSTEM user.

What can I do to stop these errors from the command line and the scheduled task?


Solution

  • When calling the batch file from the stored procedure I incurred errors but when I called php-cgi.exe directly and added my arguments to the arguments textbox everything ran perfectly.

    I'm guessing my batch file didn't have the proper permissions.