CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMail (Moderator: Piotr Szotkowski) »
  • mailing.* tokens cause memory leak in civimail.cronjob.php, plus another problem
Pages: [1]

Author Topic: mailing.* tokens cause memory leak in civimail.cronjob.php, plus another problem  (Read 2047 times)

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
mailing.* tokens cause memory leak in civimail.cronjob.php, plus another problem
November 18, 2011, 07:29:39 pm
On an earlier post I complained of having memory issues with civimail.cronjob.php - see http://forum.civicrm.org/index.php/topic,22211.msg93343.html

I've found the cause, and I have attached a patch. There's another issue, but I'm not sure how to resolve that.

Our CiviMail Mailing header includes the mailing.viewUrl token. During the processing of each email CRM_Mailing_BAO_Mailing::getTokenData() is called to process this token. Here's the code for mailing.* tokens ...
Code: [Select]
        } else if( $type == 'mailing' ) {
            require_once 'CRM/Mailing/BAO/Mailing.php';
            $mailing = new CRM_Mailing_BAO_Mailing( );
            $mailing->find( true );
            if ( $token == 'name' ) {
                $data = $mailing->name ;
            } else if ( $token == 'group' ) {
                $groups = $mailing->getGroupNames( );
                $data = implode(', ', $groups);
            }         
        } else {

The creating and populating of a new CRM_Mailing_BAO_Mailing has two issues ...
  • When I use CRM_Utils_System::memory() it tells me that memory usage increases by 3Mb each time this is called. Commenting out the call resolves the memory issue.
  • The find() call populates the CRM_Mailing_BAO_Mailing with the content of the first mailing - not this mailing. I suspect if I was using the mailing.name token I'd get a surprise!

I think the fix should be ...
  • Only do a 'new' and a 'find' if they're needed - ie when the token is mailing.name or mailing.group
  • Review whether 'new' and 'find' are actually needed - why not use $this rather than $mailing?

Ken
« Last Edit: November 18, 2011, 07:47:54 pm by ken »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: mailing.* tokens cause memory leak in civimail.cronjob.php, plus another problem
November 19, 2011, 06:54:05 am

good detective work :)

However i could not find the below code in either 3.4 / 4.0 or 4.1 (i even looked in 3.3!)

so not sure how that code is in your install and not in svn

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
Re: mailing.* tokens cause memory leak in civimail.cronjob.php, plus another problem
November 19, 2011, 02:35:22 pm
The code was added to trunk as r26463 as part of CRM-5058. The patch I attached was taken from the Drupal tar file for 3.4.7. Here it is again as a quote ...
Code: [Select]
--- /data/Download/CiviCRM/civicrm-3.4.7-drupal/./CRM/Mailing/BAO/Mailing.php 2011-08-23 20:28:46.000000000 +1000
+++ /data/Work/IT/CiviCRM/Local/3.4.7/php/./CRM/Mailing/BAO/Mailing.php 2011-11-19 14:35:57.574287583 +1100
@@ -1239,13 +1239,10 @@
             $domain =& CRM_Core_BAO_Domain::getDomain( );
             $data = CRM_Utils_Token::getDomainTokenReplacement($token, $domain, $html);
         } else if( $type == 'mailing') {
-            require_once 'CRM/Mailing/BAO/Mailing.php';
-            $mailing = new CRM_Mailing_BAO_Mailing( );
-            $mailing->find( true );
             if ( $token == 'name' ) {
-                $data = $mailing->name ;
+                $data = $this->name ;
             } else if ( $token == 'group' ) {
-                $groups = $mailing->getGroupNames( );
+                $groups = $this->getGroupNames( );
                 $data = implode(', ', $groups);
             }         
         } else {

I've tested that commenting out the 'new' and 'find' stop the memory leak. However, I'm not sure if changing '$mailing' to '$this' works, as I don't really understand the contexts in which this code is used.

Ken

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: mailing.* tokens cause memory leak in civimail.cronjob.php, plus another problem
November 20, 2011, 06:58:43 am

can u please file an issue. we'll take a look and fix this for 4.1

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
Re: mailing.* tokens cause memory leak in civimail.cronjob.php, plus another problem
November 20, 2011, 04:07:36 pm
Created issue CRM-9217

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMail (Moderator: Piotr Szotkowski) »
  • mailing.* tokens cause memory leak in civimail.cronjob.php, plus another problem

This forum was archived on 2017-11-26.