我嘗試使用我的cron php腳本創建下一個發送郵件。 我使用Zend_View來渲染電子郵件模板。 我有5萬用戶,但有3000封電子郵件是用64MB內存限制和7200用128MB創建的。在Zend Framework視圖渲染需要大量內存
foreach ($users as $user) {
.....
$text = Mailer::getInstance()->prepareEmailBody($template, $vars);
.....
}
代碼渲染電子郵件
public function prepareEmailBody($template, $templates)
{
$view = new Zend_View(array('basePath' => './application/views'));
$template_file_name = $template . '.phtml';
foreach ($templates as $key => $value) {
$view->$key = $value;
}
$body = $view->render('mails/' . $template_file_name);
return $body
}
,並使用此方法的請指點如何優化代碼。
您還沒有提供足夠的代碼。你剛剛粘貼的只是一個Zend_View。無論如何,歡迎來到Zend_Framework的世界。這是內存密集型..這就是爲什麼你應該使用APC和緩存一切。 – Layke
我無法緩存呈現的視圖,因爲每個用戶的數據都粘貼在此模板中。 – Dmitro
真正的問題是使用視圖渲染,因爲如果我寫$ text ='一些文本';然後創建所有50k電子郵件。 – Dmitro