dsvcqvp139098 2014-01-17 04:32
浏览 48
已采纳

密件抄送电子邮件需要很长时间才能使用YiiMail发送。 有没有办法加快速度?

I have this function that whenever an admin posts a new announcement, it sends an email to all the users of the forum:

 $currentid = Yii::app()->db->createCommand("select id from content where id = (select max(id) from content)")->queryRow();
                Yii::app()->session['announcement_message'] = 'You have successfully created an announcement.';

                $url = Yii::app()->createAbsoluteUrl('announcement/view/id/'.  $currentid["id"]);
                if(Yii::app()->partyroles->isAdmin())
                    {
                        $this->emailAll($url);
                    }
                $this->redirect(array('view','id'=>$model->id));

the emailAll() is another function that I made to do the actual mail sending but since there could be 100's to 1000's of emails in the future, the sending would be slow! Whenever I click the "create" button, it usually takes around 30 seconds before it redirects back to the view page since it takes a while to send all of those emails.

My question is if there's any way to speed this up? Or is there any clever way to perhaps show the user that "Email's are being sent, please wait?"

  • 写回答

1条回答 默认 最新

  • douliwang6896 2014-01-17 05:08
    关注

    For such a number of recipients I would not send the emails from the script that creates the newsletter, but write filter for the emails and the other informations as job into a queue, which is then read by another process (e.g. triggered by cron job) that builds the list of emails using the filter and then sends the email. You could store the job with an id in the queue so that you could check with e.g. ajax if the job is done.

    This will additionally allow your system to schedule the sending of emails if it is for some reason busy.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败