2011-05-27 25 views
4

可能重複:
What is the Windows version of cron?運行 「cron的」 Windows服務器上的工作

大家好,

我在IIS服務器上的script.php,我想每x分鐘自動調用一次該腳本。問題是我需要將參數傳遞給腳本,就像我在瀏覽器(script.php?task = aaa)中那樣。似乎計劃任務忽略參數?task = aaa ...

我該如何運行此腳本傳遞一些「GET」參數?

感謝, 大號

+3

沒辦法是一個重複。完全不同的問題.. – WhiskeyTangoFoxtrot 2011-05-27 17:09:49

+0

在Windows中,cron作業被稱爲計劃任務,您可以在控制面板中找到它。 – Drewdin 2011-05-27 19:35:34

+2

這絕對是一個不同的問題,因爲我在發佈之前閱讀了這個答案,並且沒有發現關於傳遞參數的答案。與往常一樣,我唯一能說的是:噢,好吧 – luigi7up 2011-05-30 07:56:51

回答

4

您可以通過調用它像這樣把參數文件:

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

和那麼你可以用這個函數解析argv:

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 

來源:http://php.net/manual/en/features.commandline.php

6

我在Windows 2003服務器上有兩次這樣的cron作業。我使用我可以工作的網址編寫iexplorer的計劃任務。

例如:

「C:\ PROGRAMFILES \的Internet Explorer \ IEXPLORE.EXE」 http://mydomain.com/admin/index.php?action=central_alertas.php&act=1

+1

如果他沒有運行httpd會怎麼樣? – WhiskeyTangoFoxtrot 2011-05-27 17:03:22

+1

這是一個公平的建議,如果人在php腳本。 – U62 2011-05-27 17:29:17

+1

我只是好奇:在運行腳本後,IE應該如何退出?或者他們是否應該有另一項關閉它的任務? – mavrosxristoforos 2013-08-30 04:45:57

相關問題