そもそもphp上で接続するのではなくブラウザに終了を認識させればいいので
ob_startとob_get_lengthなどを使い
headerでContent-LengthとConnection: closeを出力する方法がマッチしているのではないかな
適当にググってみたけど下のサイトがわかりやすかったかな
ttps://pisuke-code.com/php-send-response-immediately/