代码之家  ›  专栏  ›  技术社区  ›  Selvamani P

CronJob未在Drupal7中自动运行

  •  0
  • Selvamani P  · 技术社区  · 7 年前

    家庭管理配置系统

    在管理面板cronsetting页面中,检查 强制运行

    function hello_cronapi($op, $job = NULL){
       $items['example_sendmail_cron'] = array(
        'description' => 'Send mail with news',
        'rule' => '* * * * *', // Every 5 minutes
      );
    
      $items['example_news_cron'] = array(
        'description' => 'Send mail with news',
        'rule' => '*/15 * * * *', // Every 5 minutes
        // i must call: example_news_fetch('all')
        'callback' => 'example_news_cron',
        'arguments' => array('all'),
      );
        return $items;
    

    }

    函数示例_sendmail\u cron(){

        echo "Company"; 
        $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
        $txt = "John Doe\n";
        fwrite($myfile, $txt, FILE_APPEND | LOCK_EX);
        $txt = "Jane Doe\n";
        fwrite($myfile, $txt, FILE_APPEND | LOCK_EX);
        fclose($myfile);
    
        exit;
    }
    function example_news_cron() {
    
        echo "Company"; 
        $myfile = fopen("newfile2.txt", "w") or die("Unable to open file!");
        $txt = "John Doe\n";
        fwrite($myfile, $txt, FILE_APPEND | LOCK_EX);
        $txt = "Jane Doe\n";
        fwrite($myfile, $txt, FILE_APPEND | LOCK_EX);
        fclose($myfile);
    
        exit;
    }
    

    在上面的cronjob中,创建一个文件并将内容放入该文件中。但文件不是创建的

    1 回复  |  直到 7 年前
        1
  •  1
  •   Geoffray Warnants    7 年前

    Drupal cron不是自动运行的,它们是在用户点击您的页面时运行的。如果您想要定时运行,则必须在Web服务器上设置cron任务。

    https://www.drupal.org/docs/7/setting-up-cron-for-drupal/configuring-cron-jobs-using-the-cron-command