如何在后台代码初始化器中调用函数 [英] how to call function in background codeigniter

查看:75
本文介绍了如何在后台代码初始化器中调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的系统需要向许多用户发送电子邮件,并且确实需要花费时间才能发送许多用户。我不想让用户等待时间。

My system needs to send email to many users, and it really takes time to send many users. I do not want users to wait that time.

_send_mail函数在每种用途的不同控制器文件中。有什么方法可以在后台发送电子邮件?

_send_mail functions are in various controller file per purpose. Is there any way we can send email in background?

推荐答案

在这种情况下,您可以在发送邮件之前返回部分回复。因此,您将得到进一步的响应,并且电子邮件发送过程将在后台继续进行。

In this case, you can return a partial response before sending your mail. So you will get a response to proceed further and your email sending process will continue in the background.

为此,请创建一个函数,该函数将抛出如下所示的分区响应

To do this create a function which will throw a partition response like this

    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();
    }

并在发送电子邮件之前调用此功能

and call this function before sending email

 $this->partialResponse();

此操作之后,无论您要做什么,即发送电子邮件

after this DO whatever you want to do i.e Send the email

注意:这仅在apache服务器上进行了测试。不适用于nginx。

NOTE: This is tested with apache server only.This will not work for nginx.

这篇关于如何在后台代码初始化器中调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆