Laravel 4 with nikic phpparser: out of memory when sending email

Just found out that Laravel uses nikic phpparser internally.

I changed my code to send letters according to one of the conditions, and he began to die.
PHP logs showed this:

[Sat Oct 03, 21:18:23 2015] [error] [client xx.xx.xx.xx] PHP Fatal Error: the valid memory size of 33554432 bytes has been exhausted (tried to allocate 1048576 bytes) in / home / yyyy / public _html / vendor / nikic / php-parser / lib / PHPParser / NodeTraverser.php on line 66, referent: http://yyyy.com/home

I temporarily increased my memory to solve the problem.
But I want to move away from the striped help. I see that the NodeTraverser function is doing the cloning, which will cause the problem:

protected function traverseNode(PHPParser_Node $node) { ini_set('memory_limit', '64M'); // temporary fix $node = clone $node; foreach ($node->getSubNodeNames() as $name) { $subNode =& $node->$name; if (is_array($subNode)) { $subNode = $this->traverseArray($subNode); } elseif ($subNode instanceof PHPParser_Node) { foreach ($this->visitors as $visitor) { if (null !== $return = $visitor->enterNode($subNode)) { $subNode = $return; } } $subNode = $this->traverseNode($subNode); foreach ($this->visitors as $visitor) { if (null !== $return = $visitor->leaveNode($subNode)) { $subNode = $return; } } } } return $node; } 

This is how I send an email. This is no different from anywhere else, so I doubt it will cause a problem:

  $this->mailer->queue('emails.forreg', [ 'toName' => $toEmailName, 'fromName' => $user->username, 'site_name' => \Config::get('site_title') ], function($mail) use($toEmailAddress, $user, $subject_to_send, $toEmailName) { $mail->to($toEmailAddress, $toEmailName) ->subject($subject_to_send) ->from(' xxx@yyy.com ', $user->username); } ); 

Any ideas on how to resolve this?

+6
source share
1 answer

You just have a limited memory limit. The PHP IIRC limit starts at 128M by default. When the parser passes through it, a node is created for each individual piece of code. Nothing is excluded, and there is no easy hot fix.

Memory is cheaper than ever today, and this problem is unlikely to be fixed due to the upcoming PHP7. Perhaps let's try, because in any case, there may be less memory used.

0
source

All Articles