php 使用方法 ignore_user_abort(true);

php 使用方法 ignore_user_abort(true);后 同一个方法使用两次 ,服务会挂是什么原因

方法在这里。意思是程序在前端显示结束了,但后端在继续执行,为了拯救前端的体验,防止客户端等待时间过长。先返回一个假的 成功请求的回复,但是需要等待后端执行完。这个现在已经不流行了。

你可以弄个swoole 异步任务去执行。

$set_time_limit = 0;
    if (function_exists('fastcgi_finish_request')) {
        fastcgi_finish_request();
    } else {
        $size = ob_get_length();
        header("Content-length: $size");
        header('Connection:close');
        ob_end_flush();
        flush();
    }
    ignore_user_abort(true);
    set_time_limit($set_time_limit);
    ini_set('memory_limit', '50000M');
    ini_set('max_execution_time', 0);