Memory limit :(

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
saiaman
Forum Newbie
Posts: 8
Joined: Mon Oct 06, 2008 10:03 am

Memory limit :(

Post by saiaman »

I've got this problem while working with swift

PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 35 bytes) in ****************/include/Swift/classes/Swift/CharacterStream/ArrayCharacterStream.php on line 267


Can anybody help ???

Thank you
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Memory limit :(

Post by Chris Corbyn »

Please can you post your code? How many emails are you trying to send too? And lastly, how big are the emails?
saiaman
Forum Newbie
Posts: 8
Joined: Mon Oct 06, 2008 10:03 am

Re: Memory limit :(

Post by saiaman »

The fact is that i can't post the code ... but i can explain what i'm doing maybe you'll find out the issue :

in a script i unserialize data issue from a file containing : 1 swift message and 1 PHP array providing the list of emails.
Then i pass this parameters to a multithread daemon.

In this daemon there are two main methods : getNext and run


_construct:

Code: Select all

        
$this->message=$message;
        unset($message);
        $this->list = $list;
        unset($list);
        $this->total = count($this->list);
 
        foreach($this->tabServers as $ip){
            $this->transports[] = new Swift_Mailer(new Swift_SmtpTransport($ip,25));
        }
 
 
getNext :
pops the last element from the array providing the email adresse to target

run:
this methods is launched in a child process

Code: Select all

 
        $t = $slot%count($this->tabServers);
        $mailer = &$this->transports[$t];
        $this->message->getHeaders()->addTextHeader("X-******",$next);
        $mailer->registerPlugin(new Swift_Plugins_DecoratorPlugin(new GibReplacements()));
        $this->message->setTo($next);
        $mailer->send($this->message);
 
 
Last edited by Benjamin on Mon May 18, 2009 10:41 am, edited 1 time in total.
Reason: Changed code type from text to php.
saiaman
Forum Newbie
Posts: 8
Joined: Mon Oct 06, 2008 10:03 am

Re: Memory limit :(

Post by saiaman »

The creation of the swift message consumes a lot of memory :

Code: Select all

 
2009-04-10 10:46:31 [3406] INFO : Memory USAGE   499764
2009-04-10 10:46:31 [3406] INFO : Initialisation of message
2009-04-10 10:46:31 [3406] INFO : Memory USAGE 1693656
 
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Memory limit :(

Post by Chris Corbyn »

Yeah Swift uses around 2MB. That's a lot less than your memory limit though (~100MB).

I'm not clear on where you're calling registerPlugin(). Are you registering a plugin for every single message sent? Also, which version of the library do you have? Is it version 4.0.3 or an earlier variant of version 4?
saiaman
Forum Newbie
Posts: 8
Joined: Mon Oct 06, 2008 10:03 am

Re: Memory limit :(

Post by saiaman »

Yes the plugin was registered in each child process. So for each mail. But this has been modified.

I was using version 4.0.3 of swift.
But this memory problem seems to appear while building the message ( encoding ? ) before sending.
DarkRaver
Forum Newbie
Posts: 1
Joined: Mon May 18, 2009 7:00 am

Re: Memory limit :(

Post by DarkRaver »

Hi all,
Is there a solution/workaround out there to the memory limit problem ?
I face this problem and can't push the memory limit too high ! (already 128M)

It looks like the problem is related to the CharacterStream and/or the ByteStream and/or UTF8 stuff that seems to be java classes ported to php.

Can we tell/configure Swift not to use these classes when we're sure to have both the scripts and the data being part of the message already utf8 encoded ?

What is the benefit of having all that classes encoding data in utf8 when everything is allready utf8 encoded ?

We (I and my company) are completely stuck with Swift crashing with memory exhausted messages as soon as the messages are more than a (very) few megabytes long.

PS : we don't use any plugin at the moment so I'm quite sure they're not the origin of the problem.

Sorry for my bad english, and hoping in a response soon.

Thanks
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Memory limit :(

Post by Benjamin »

Please post your code. In order for Chris to spend time to diagnose this issue we need to verify that the problem lies in Swfitmailer, and not your code.
Post Reply