5

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

3
  • Use fastcgi_finish_request(); Commented May 17, 2018 at 5:07
  • @ErnestasStankevičius You should post that as an answer and mention what it does and why it fixes the OP's problems. Commented May 17, 2018 at 5:09
  • @ErnestasStankevičius, I forget to mention that in my question. Updated the question. Used fastcgi_finish_request but it too not working. Commented May 17, 2018 at 5:10

1 Answer 1

1

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();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.