1

I am maintaining a Drupal 6 installation. The task was to send an email to all registered users. I was using a rule set containing one rule with a default action: "send email to all users of a certain role". The rule set has been scheduled, was executed and deleted from the schedule (automatically like expected), but the task seemed to restart forever in the background: all (or probably a lot) users got the email every hour (6 times until I stoped cron). I use poormans-cron.

Please help with to answer this questions:

  1. I suppose the mails could not be sent (~300 users) in the 60 minutes before the next cron (1h) decided that the job was still not complete and restarted it. Correct?
  2. 300 mails in 1 hour should not be a problem, but I saw somewhere, but cannot remind where, that one can set a wait time between sending mails. Is that correct? Please tell if you know where.
  3. Can you think of something else than 1. for the reason? (I used out of the box drupal 6 functions).

The log shows:

error   cron    18/02/2012 - 12:04  Cron has been running for more than an hour and is most likely stuck.
warning cron    18/02/2012 - 11:08  Cron run exceeded the time limit and was aborted.
error   cron    18/02/2012 - 11:04  Cron has been running for more than an hour and is most likely stuck.
warning cron    18/02/2012 - 10:07  Cron run exceeded the time limit and was aborted.
error   cron    18/02/2012 - 10:03  Cron has been running for more than an hour and is most likely stuck.
warning cron    18/02/2012 - 09:07  Cron run exceeded the time limit and was aborted.
error   cron    18/02/2012 - 09:03  Cron has been running for more than an hour and is most likely stuck.
error   cron    18/02/2012 - 09:02  Cron has been running for more than an hour and is most likely stuck.
error   cron    18/02/2012 - 07:50  Cron has been running for more than an hour and is most likely stuck.
warning cron    18/02/2012 - 06:46  Cron run exceeded the time limit and was aborted.

Appendix 1, 19.2.2012
I use PHPMailer module to send the emails.

1

I think that your PHP configuration is not letting cron finish. Turn off poormanscron, then delete your cron entries in your MySQL database:

DELETE FROM `variable` WHERE name = 'cron_semaphore';
DELETE FROM `variable` WHERE name = 'cron_last';

Then go to admin/reports/status and click on your PHP version to see the output of phpinfo(). What is the max execution time? What is the memory limit? You'll want to change those values to higher numbers, then verify that they are indeed different on this page, then run cron manually at admin/reports/status.

To change these 2 values in PHP, create (or edit) php.ini in the webroot of your site and add (or modify):

max_execution_time = 300
memory_limit = 256M

Obviously feel free to try whatever numbers you'd like here. Ideally you don't want to leave the memory limit very high if you don't need to.

  • I ignored your questions about changing the number of emails sent per cron as I do not know how you can set that from within Rules in D6. Perhaps that is not possible. – Charlie Schliesser Feb 18 '12 at 17:38
  • Thankyou very much for your advice. The following values are currently outputed by phpinfo: max_execution_time=600, memory_limit=128M. I will try setting it to 3000 (50min) and 256M. I really hope that it does not load all mails into memory before sending it? ;-) – spikey Feb 19 '12 at 8:34
  • Report back about how it goes. Does PHPMailer module handle any kind of queuing, i.e. can you possibly set the number of emails sent per cron run? – Charlie Schliesser Feb 19 '12 at 16:57
  • No luck. :-( I deleted the DB entries, raised the execution time/memory limit values. Enabled PHPMailer loging. Now, I will try to find those logs, because there were no additional entries in the watchdog. – spikey Feb 21 '12 at 9:23
  • php_error.log is promising: PHP Fatal error: Maximum execution time of 600 seconds exceeded in \image.imagemagick.inc on line 162 – spikey Feb 21 '12 at 9:28
0

I found the problem and changed a file in drupal core: includes/common.inc, line 2714:

function drupal_cron_run() {

  // Try to allocate enough time to run all the hook_cron implementations.
  if (function_exists('set_time_limit')) {
    @set_time_limit(240); // will return a fatal error, if the script runs more than 4min
  }
...

I changed the set_time_imit(240) line to:

    @set_time_limit(2400); 

because sending all mails lasts about 14min.

Thanks anyone for your time. Spikey

  • 1
    Alternately you can do this hack in cron.php so at least you can replace the file after an update. – AyeshK Nov 3 '12 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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