ob_start();
// do initial processing here
echo $response; // send the response to the client
header('Connection: close');
header('Content-Length: '.ob_get_length());
ob_end_flush();
ob_flush();
flush();
//... continue other stuff
//...
These two lines are very important and do the job:
header('Connection: close');
header('Content-Length: '.ob_get_length());
without them the client still hang.