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.

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

报告相同问题?

悬赏问题

  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人