I recently had to write a webhook handler that was supposed to return a "200 OK" response immediately before continuing to process other long running tasks.
I have observed that the process of hanging up immediately was never possible when I the entire process was happening using the same web server. So if the client IP of connection where you need to send a response is the same as the server IP, you might never be able to do it. But it always worked when the incoming connected was a real world remote client.
With all that said, I was just returning a "200 OK" response. Which should not be different than sending back a redirection.
The code that worked for me was ...
public function respondASAP($responseCode = 200)
{
// check if fastcgi_finish_request is callable
if (is_callable('fastcgi_finish_request')) {
/*
* This works in Nginx but the next approach not
*/
session_write_close();
fastcgi_finish_request();
return;
}
ignore_user_abort(true);
ob_start();
http_response_code($responseCode);
header('Content-Encoding: none');
header('Content-Length: '.ob_get_length());
header('Connection: close');
ob_end_flush();
ob_flush();
flush();
}
You could adapt it to your situation and make it set a redirection header instead of an "200 OK".