send response and continue processing

php Отправить http ответ клиенту и продолжить работу скрипта - пример

Можно так:

function sendResponseAndContinue(string $responce = 'Done') {
    ob_start();
    print($responce);
    header('Connection: close');
    header('Content-Length: ' . ob_get_length());
    ob_end_flush();
    @ob_flush();
    flush();
    fastcgi_finish_request();
  }

// Пример использования:

sendResponseAndContinue(); // отправиляем ответ

// делаем, что нужно

exit; // завершаем скрипт

также можно прочитать про фукции и использовать их:

Subscribe to RSS - send response and continue processing