1

Is there a way to know if the last cron run automatically or manually from the form "run cron" button?

3
  • No, there's nothing built in. Both methods call drupal_cron_run() without leaving any clue as to the origin.
    – Clive
    Apr 15, 2014 at 21:59
  • @Bouessetta, any particular reason why you would want to know if it was ran automatically or manually?
    – Randell
    Apr 15, 2014 at 23:28
  • @Randell, because many people use the website, and I doubt about the execution of some crons, so I want to be sure if that cron was automatically run(so it works fine), or if someone hundle the form (in that case my cron is not working properly) Apr 16, 2014 at 9:27

2 Answers 2

2

I'm not sure why you really want to check this. However, I can think of a few methods:

  1. Alter the admin/reports/status/run-cron menu router item, and add some flagging to mechanism to detect the call. If the user runs cron through this page, that's definitely a manual "Run Cron" call. Implement hook_menu_alter, and change page callback (probably file and file_path aswell) to your own function. In this function, add some flagging mechanism, and run previous page callback. It's unlikely that another module will need overwrite the page callback so you are almost safe. A little performance hit during menu rebuilds.

  2. Add your own cron handler, and check $_GET['q'], or better, $_SERVER['PHP_SELF']. For $_SERVER['PHP_SELF'], if it's index.php, that's a manual run. Otherwise it will be cron.php, which is likely an automatic call. However one could click the URL containing the token, which is not actually an automatic. I think this is the best method since it does not need to assume other modules does not need to override page callback. A little Performance hit in each cron run.

  3. Hack the cron.php (better yet, copy it to a new file). For example, copy cron.php file to scron.php, and make your crontab request that file instead of the the regular cron.php with token. You can then edit the scron.php file, and right after the bootstrapping, add a custom code to flag the cron that the file is about to execute is an automated one. Requires some custom effort that you can't do with a regular hook_install implementation. Performance wise, this will work almost same since there are no any hooks involved.

2
  • Good thought for 1 and 2, but didn't understand your question (3rd part) of your answer! Apr 16, 2014 at 9:42
  • Updated the answer.
    – AKS
    Apr 16, 2014 at 10:58
1

I think that if you have dblog enabled, you should be able to check the referrer in the log where it says "Cron run completed.".

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.