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:

span class="st0">"Connection: close\r\n""Content-Encoding: none\r\n"// optional
'Text user will see'"Content-Length: $size"// Strange behaviour, will not work
// Unless both are called !
//do processing here
'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.