Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP 7 continue execution after sending response

I am trying to send a response data to the client from a function and continue the execution. I followed the below code

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

Got the code from the question

continue processing php after sending http response

What I am getting is a 200 ok response only but not the data which I echoed.

I need to get the response data too. I am using php7.1. Is there any difference of use between php5 and 7?

Please help

like image 378
Arun Avatar asked Nov 07 '22 06:11

Arun


1 Answers

All you need to do is

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();
}
like image 141
metodi25 Avatar answered Nov 15 '22 13:11

metodi25