0
我的服务器连接看起来像不稳定的原因,有时会成功发送电子邮件,有时会失败。重新发送电子邮件与try catch导致内存超出限制?
错误说
Swift_TransportException
Connection to ssl://in-v3.mailjet.com:465 Timed Out
在上述情况下我试图改变的代码重新发送电子邮件,如果异常被捕获。
这是我在控制器中的代码。
//this line after import class
ini_set('memory_limit', '256M');
public function resend_on_error($tried)
{
try{
$message = Yii::$app->mail->compose();
if (Yii::$app->user->isGuest) {
$message->setFrom('[email protected]');
} else {
$message->setFrom(Yii::$app->user->identity->email);
}
$message->setTo(Yii::$app->params['adminEmail'])
->setFrom(Yii::$app->params['adminEmail'])
->setTo("[email protected]")
->setSubject('Reset Password '.$tried)
->setHtmlBody($this->renderAjax('//email/_konten',['content'=>'goes here']))
->send();
return 1;
}catch(\Swift_TransportException $e){
$this->resend_on_error($tried++);
}
}
public function actionEmail()
{
$tried = 1;
if($this->resend_on_error($tried) == 1){
return "send success";
}
}
但我得到这个
Allowed memory size of 268435456 bytes exhausted (tried to allocate 4096 bytes)
请告诉我,我做错了什么吗?
在此先感谢。
您在PHP方面的内存不足。检查php配置中的memory_limit并将其设置得更高一些。问题是,你的服务器为什么要消耗这么多的内存? – R13e
@ R13e,因为用我上面的代码重新发送电子邮件,对吗? –
可能的,但我不认为这是原因。如果我理解正确,重新发送过程只会尝试分配20480字节。那根本不算什么。 – R13e