Why do only certain Cron intervals run?

I noticed that on my_website/admin/cron page (Elgg3.3.2) only certain Cron intervals run for example fiveminute, fifteenminute, halfhour, and hourly. But daily, weekly, and monthly do not. Why is that?

Explanation or clarification would be greatly appreciated.

  • Maybe you don't have triggers for these intervals?

    Anyway, you can activate handlers for a specific interval:

    @daily path/to/phpbin path/to/elgg/elgg-cli cron -i daily -q
  • Thanks for a quick response RvR!

    I do have a trigger in the start.php of my plugin like elgg_register_plugin_hook_handler('cron', 'daily', 'my_cron');

    I tried the approach you provided above (elgg-cli) and hit the URL like 'my_website/cron/daily' BUT when I checked the admin/cron page, the status of daily cron is still 'Never'.

  • 1 - Something wrong with your plugin's hook (wrong code, access permission etc).

    2 - Protected Cron URLs - look at admin/security section: Administration -> Security

    Tip:

    You can remove -q flag temporary if you want cron logs to be saved on your server.

    Trick:

    Disable protection of your cron URLs.

    Run this command:

    curl https://site.com/cron/daily/

    To check that cron trigger is exists and runs.

    Notes:

    For testing you can use an -i and -f flags:

    • -i for internval name, 
    • -f for force run even if job is not due.

    You no longer need to setup a gazillion jobs for each period.

    You only need to setup one cron job that hits the main command every minute.

    Elgg's cron handler will determine which cron handlers are due and will run them.

  • 1. elgg_register_plugin_hook_handler('cron', 'daily', 'my_cron');

       function my_cron(\Elgg\Hook $hook) {

            error_log('testing my cronjobs');

       }

    That is my hook - just for testing. But it did not return the error message in the httpd log.

    2. I checked admin/security section and 'Protect the /cron URLs' is disabled. 

     

  • It's on the dev environment so it is not on SSL.

  • Then force your cronjob:

    php path/to/elgg/elgg-cli cron -i daily -f

     

    And use something like this:

    echo "testing my cronjobs" . PHP_EOL;
    
    elgg_log("testing my cronjobs", 'NOTICE');
     
    Not error_log.
  • Thanks RvR! 

    Now I saw that message in the terminal window as well as the cron log for 'daily' interval in admin/cron.

  • Another issue I found regarding cronjobs. Daily cron runs as expected but it does not show the log in Admin > Information > Cron. It shows the log only when I manually run the vendor/bin/elgg-cli cron -i daily -f. 

  • Make sure the cron account and the webserver account are the same.

    Otherwise the cron account will write the logfile, but the webserver won't be able to read it

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking