php response.write,发送http响应后继续处理php

我在这个问题上花了几个小时,我附带了一个在Apache和Nginx上工作的函数:/**

* respondOK.

*/protected function respondOK(){

// check if fastcgi_finish_request is callable

if (is_callable('fastcgi_finish_request')) {

/*

* This works in Nginx but the next approach not

*/

session_write_close();

fastcgi_finish_request();

return;

}

ignore_user_abort(true);

ob_start();

$serverProtocole = filter_input(INPUT_SERVER, 'SERVER_PROTOCOL', FILTER_SANITIZE_STRING);

header($serverProtocole.' 200 OK');

header('Content-Encoding: none');

header('Content-Length: '.ob_get_length());

header('Connection: close');

ob_end_flush();

ob_flush();

flush();}

您可以在长时间处理之前调用此函数。