douqian1296 2019-04-12 10:02
浏览 51

在后台codeigniter中调用函数

I want to send mail in the background, I have a function for it, and it's working fine, but it is blocking my message to pass to the user!

// i tried this

$er=1; 
$outmsg = 'You are now registered,please check your email for verification!';
$this->common_model->partialResponse();
$this->mailer->send_mail($mail,$Mailconfig);
$type = ($er==1) ? "success" : "danger";
echo json_encode(array('msgtype'=>$type,'datacon'=>$outmsg));



function partialResponse()
  {
     $response=array();
     ignore_user_abort(true);
     ob_start();
     echo json_encode($response);
     header("Status: 200");
     header($_SERVER["SERVER_PROTOCOL"] . " 200 Ok");
     header("Content-Type: application/json");
     header('Content-Length: '.ob_get_length());
     ob_end_flush();
     ob_flush();
     flush();
 }
  • 写回答

1条回答 默认 最新

  • duanleiming2014 2019-04-12 11:46
    关注

    Recently I endup with the same problem: slow email sending. Using SMTP is even worse. 3~4 seconds to send the e-mail.

    At first thouths I think I could do something you are trying to archieve, but this method can cause so many problems, that did not worth it.

    I endup creating a email table, to queue (and save as history) all emails that might be sent.

    For process this queue I created a cronjob to run a specific controller/method just to send those emails.

    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错