2012-02-13 37 views
0

我正在爲客戶端構建一個Drupal 6模塊,我希望每XYZ分鐘執行一部分代碼。我知道我可以實現cron_hook,但是我的模塊無法控制客戶端的cron。我需要運行我的代碼而不考慮cron設置。任何想法如何解決這個問題?Drupal Cron Hook

回答

2

Drupal並沒有提供任何超越hook_cron功能的東西。

但是,你可以做的是定義一個正常的菜單回調,它執行任何想要運行的代碼代碼。只需手動設置工作在你的服務器的cron選項卡來啓動它,只要你想

<? 
function example_menu() { 

    $items = array(); 
    $items['example/cron'] = array(
     'title' => 'example Cron', 
     'page callback' => 'example_callback', 
     'type' => MENU_CALLBACK, 
    ); 

} 

function example_callback(){ 
     //optionally do some IP checking to make sure its not being fired by a remote request 

     set_time_limit(0); //set it so your cron wont time out if it takes a long time to process ... be careful your cron doesnt run forever though 

     watchdog('example', "Cron Started", array(), WATCHDOG_NOTICE); 
     //execute custom code here 
     for($i = 0; $i < 100; $i++){ 
     //do stuff 
     } 

     watchdog('example', "Cron Complete", array(), WATCHDOG_NOTICE); 

    } 

一旦你的,只是成立一個cron作業打網址但是往往你想

X Y * * * curl http://examplesite.com/example/cron 
+0

感謝您的迴應。謝謝!! – 2012-02-16 20:03:02