Zend Framework 视图渲染占用大量内存
我尝试使用 cron php 脚本创建用于下次发送的电子邮件。 我使用 Zend_View 来渲染电子邮件模板。 我有 50k 用户,但在 64MB 内存限制下创建了 3000 封电子邮件,在 128MB 内存限制下创建了 7200 封电子邮件。 渲染电子邮件的代码
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
}
中使用此方法。
foreach ($users as $user) {
.....
$text = Mailer::getInstance()->prepareEmailBody($template, $vars);
.....
}
并在请建议如何优化代码
I try to create emails for next sending with my cron php script.
And I use Zend_View for rendering email template.
I have 50k users but 3000 emails was created with 64MB memory limit and 7200 with 128MB.
Code of rendering emails
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
}
And use this method in
foreach ($users as $user) {
.....
$text = Mailer::getInstance()->prepareEmailBody($template, $vars);
.....
}
Please advice how optimize code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用一个 View 对象和部分助手,这可能会改善情况(或者可能会使速度变慢)。
You could try using one View object and the partial helper instead, this might improve things (or might make it slower).