Posted by Kelvin on 03 Feb 2014 at 12:15 am | Tagged as: PHP
Here's one way to send and close the connection to the client and for the PHP script to continue processing, presumably to perform some processing that is time-consuming:
ignore_user_abort(true); // optional
echo ('Text user will see');
$size = ob_get_length();
ob_end_flush(); // Strange behaviour, will not work
flush(); // Unless both are called !
//do processing here
echo('Text user will never see');
//do some processing
Note that some stackoverflow answers which mention the use of ignore_user_abort are mistaken. That's not required at all. And you'll need the Content-Encoding: none header, otherwise it won't work properly with clients that accept gzip encoding for example.