Newsletter Plugin: Cron failing

By gversion - October 3, 2013

The following Background Task did not complete successfully:

Date/Time:2013-10-03 15:48:02Activity:Newsletter MailerSummary:Returned errorsCompleted:0Function:nlb_mailerOutput:Sending queued 'Background Send' emails, (552 queued, sending max 500 per batch)

Sending message to .........hidden for privacy..........

Fatal error: Maximum execution time of 30 seconds exceeded in /home/mydomain/public_html/cmsAdmin/3rdParty/SwiftMailer/classes/Swift/CharacterReader/Utf8Reader.php on line 127
Runtime:35.13 seconds

Please check the Background Tasks logs here and check for additional errors:
http://www.mydomain.com/cmsAdmin/admin.php?menu=_cron_log

You can review the Background Tasks status & settings here: 
http://www.mydomain.com/cmsAdmin/admin.php?menu=admin&action=general#background-tasks

*Please note, incomplete background task alerts are only sent once an hour.

I am unsure what the above email message means. Can someone please explain?

There were 60 email addresses listed but I have removed them for privacy reasons. I have also replaced my domain name with "mydomain" for privacy reasons.

Any help/advice would be gratefully received.

Thank you,

Greg

By gregThomas - October 3, 2013

Hi Greg,

The reason you're getting this message is that the time out limit for the PHP on your server is 30 seconds, but you're e-mailing script is taking longer than that to run. There are three ways you can fix this issue:

1) Reduce the number of messages that the script sends to 50, as this is roughly how many it sent before timing out.  You can do this in cmsAdmin/plugins/newsletterbuilder/background-mailer.php file on line 6:

  $GLOBALS['BACKGROUND_SEND_MAX']     = 50;  // max messages to send in each batch, eg: If a cronjob runs the script every 10 min and this is set to 80, you'll send approx 480 emails an hour

2) Increase/add the max_execution_time setting in your php.ini file to 120 seconds. (You could add this to the php.ini file in your cmsAdmin directory so it doesn't affect the entire site.

max_execution_time = 120; 

NOTE: Some hosting services disable this feature for security/efficiency reasons.

3) Increase the max execution time by adding a line to the background-mailer. This is not recommended as it requires changing CMSB plugin files, and we can't provide any support for issues that arise from it. If you go to around line 106 of the background mailer, you should see some code that looks like this:

 function _sendQueuedEmails() {
  $newsletterSettings  = mysql_get('_nlb_settings', 1);
  $count               = 0;
  $sendErrors          = '';
  $messagesByNum  

If you add this line to the function:

 function _sendQueuedEmails() {
  $newsletterSettings  = mysql_get('_nlb_settings', 1);
  $count               = 0;
  $sendErrors          = '';
  $messagesByNum       = array();

  //Increase the maximum execution time of the script to 120 seconds.
  set_time_limit(120);

The maximum execution time of the script will be increased to 120 seconds. NOTE: Some hosting services disable this feature for security/efficiency reasons.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gregThomas - October 4, 2013

Hi Greg,

Yes, you'll need to reset the settings in the background mailer every time you upgrade. So that is something to keep in mind.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com