4

Possible Duplicate:
What is the Windows version of cron?

Hi everyone,

I'm having a script.php on IIS server and I want to call that script automatically every x minutes. The problem is that I need to pass arguments to the script like I would do in the browser (script.php?task=aaa). it seems that scheduled task ignores argument ?task=aaa...

How can I run this script passing it some "GET" arguments?

Thanks, L

Community
  • 1
  • 1
luigi7up
  • 4,783
  • 2
  • 40
  • 52
  • 3
    no way is that a duplicate. totally different question.. – WhiskeyTangoFoxtrot May 27 '11 at 17:09
  • in windows a cron job is called a scheduled task, you can find it in the control panel. – Drewdin May 27 '11 at 19:35
  • 2
    It's definitely a different question because I read that answer and few more before posting and I didn't find the answer about passing the arguments. As always the only thing I can say is: oh, well – luigi7up May 30 '11 at 07:56

3 Answers3

6

I have twice cron jobs like these on my windows 2003 server. I program a schelude task of iexplorer with the url that I can work.

For example:

"C:\ProgramFiles\Internet Explorer\iexplore.exe" http://mydomain.com/admin/index.php?action=central_alertas.php&act=1

Fran Hurtado
  • 120
  • 1
  • 10
4

You can pass parameters into the file by invoking it like so:

C:\PHP5\php.exe -f "C:\PHP Scripts\script.php" -- -arg1 -arg2 -arg3

and then you can parse argv with this function:

function arguments($args ) {
    $ret = array(
        'exec'      => '',
        'options'   => array(),
        'flags'     => array(),
        'arguments' => array(),
    );

    $ret['exec'] = array_shift( $args );

    while (($arg = array_shift($args)) != NULL) {
        // Is it a option? (prefixed with --)
        if ( substr($arg, 0, 2) === '--' ) {
            $option = substr($arg, 2);

            // is it the syntax '--option=argument'?
            if (strpos($option,'=') !== FALSE)
                array_push( $ret['options'], explode('=', $option, 2) );
            else
                array_push( $ret['options'], $option );

            continue;
        }

        // Is it a flag or a serial of flags? (prefixed with -)
        if ( substr( $arg, 0, 1 ) === '-' ) {
            for ($i = 1; isset($arg[$i]) ; $i++)
                $ret['flags'][] = $arg[$i];

            continue;
        }

        // finally, it is not option, nor flag
        $ret['arguments'][] = $arg;
        continue;
    }
    return $ret;
}//function arguments

Source: http://php.net/manual/en/features.commandline.php

3

I would suggest downloading cURL for Windows, as it can make the page request to your server for you. You can then use the Windows Task Scheduler to execute curl script.php?task=aaa.

Michael Mior
  • 26,133
  • 8
  • 80
  • 110