Re: free allocated memory: HOW ?
| From: | Arthur Erdös | Date: | Fri, 13 Apr 2007 05:49:43 +0000 |
| Subject: | Re: free allocated memory: HOW ? | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-252824@lists.php.net to get a copy of this message | ||
> Just post your source already.
>
ok, the complete workflow is a little bit complicated. we are using a
workflow engine and the newsletter generator is one step of three. the
first cleans the statistics data, the second generates the new data and
the third is the one which generates the mails.
here is the concerning method:
/**
* This method generates the monthly newsletter with the statistics
block for the specified period.
*
* @param NewsletterValue $vo Initialized NewsletterValue object
* @param Integer $dateFrom Timestamp representing the start date of
the period
* @param Integer $dateTo Timestamp representing the end date of the
period
*/
private final function generateMonthlyNewsletter($vo, $dateFrom,
$dateTo){
$this->logger->debug("Generating monthly newsletter with statistics
blocks.");
// initialize variable for the abonents
$abonents = null;
// read the newsletter template
$asset = $vo->getAsset();
$theData = self::readTemplate("../../../" . $this->templatePath .
$asset->getFileName());
$this->logger->debug("successfully read template, MEMORY USAGE: " .
memory_get_usage()/1048576 . " MB");
// iterate over the abonents and generate customized newsletter
content
$counter = 0;
$start = 0;
$offset = self::PROCESS_ABONENTS;
// get the first newsletter abonents
$personAction = new PersonEPBAction();
$abonents = $personAction->findAbonents($start, $offset);
$size = $personAction->countFoundRows();
$this->logger->debug("Found " . $size . " abonents....");
$loops = ceil($size/self::PROCESS_ABONENTS);
$this->logger->debug("Need " . $loops . " loops at " .
self::PROCESS_ABONENTS . " abonents per loop");
for($i = 0; $i < $loops; $i++){
$start = $i*self::PROCESS_ABONENTS;
$abonents = $personAction->findAbonents($start,
self::PROCESS_ABONENTS);
$this->logger->debug("Loop " . $i . ", MEMORY USAGE: " .
memory_get_usage()/1048576 . " MB");
foreach($abonents as $person){
$this->logger->debug("Generating mail for " .
$person->getPersonId() . ", " . $person->getFullName());
// replace custom person fields
$text = self::replaceTemplateVars($theData, $person, $dateFrom,
$dateTo);
// add statistics
$text = self::addStatisticsBlocks($text, $person);
// add the text to the person_newsletter table
$lvo = new PersonNewsletterLightValue();
$lvo->setNewsletterIdFk($vo->getNewsletterId());
$lvo->setPersonIdFk($person->getPersonId());
$lvo->setMimeTypeIdFk(2); // text/html TODO: refactor!
$lvo->setName("brainGuide AG"); // TODO: refactor!
$lvo->setEmail("service@brainguide.com"); // TODO: refactor!
$lvo->setMailto($person->getEmailBusiness());
$lvo->setSubject($vo->getSubject());
$lvo->setText($text);
$lvo->setTstamp(time());
$lvo->setSent(0);
$lvo->setViewed(0);
self::savePersonNewsletter($lvo);
// unset variables
// unset($text, $lvo);
$text = null;
$lvo = null;
sleep(1);
}
}
}