Just learned that Laravel using nikic phpparser internally.
I modified my code to sending emails on one of the conditions & it started dying.
The PHP logs showed this :
[Sat Oct 03 21:18:23 2015] [error] [client xx.xx.xx.xx] PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 1048576 bytes) in /home/yyyy/public_html/vendor/nikic/php-parser/lib/PHPParser/NodeTraverser.php on line 66, referer: http://yyyy.com/home
Temporarily I've increased the memory to resolve the issue.
But, I want to move away from the band-aid.
I see that the NodeTraverser function is doing a clone, would that 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'm sending the email. This is no different than anywhere else, hence I doubt this would cause an issue :
$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 ?
You simply have an extreme low memory limit. IIRC PHP limit starts at 128M for a default. When the parser goes through it's building up a node for every single part of the code. Nothing is excluded and there's no easy hot fix.
Memory is cheaper than ever today and this problem is unlikely to be fixed because of the upcoming PHP7. Perhaps give that a try as it's likely to have a smaller memory footprint anyways.