PHP 7 发送响应后继续执行

Aru*_*run 5 php fastcgi httpresponse

我正在尝试从函数向客户端发送响应数据并继续执行。我按照下面的代码

ignore_user_abort(true);
set_time_limit(0);

ob_start();
// do initial processing here
echo $response; // send the response
header('Connection: close');
header('Content-Length: '.ob_get_length());
ob_end_flush();
ob_flush();
flush();
// check if fastcgi_finish_request is callable
if (is_callable('fastcgi_finish_request')) {
    fastcgi_finish_request();
}
Run Code Online (Sandbox Code Playgroud)

从问题中得到代码

发送http响应后继续处理php

我得到的只是 200 ok 响应,而不是我回显的数据。

我也需要获取响应数据。我使用的是php7.1。php5和7的使用有什么区别吗?

请帮忙

met*_*i25 1

您需要做的就是

set_time_limit(0);

echo $response; // send the response

// check if fastcgi_finish_request is callable
if (is_callable('fastcgi_finish_request')) {
    fastcgi_finish_request();
}
Run Code Online (Sandbox Code Playgroud)