Why doesn't the Location heading redirect the page right away?
Just because it does not redirect anything at all. This is a browser that will block the current connection (which will cause the script to stop) to request another page. And there is network latency.
Does it always complete the whole process before redirecting?
Not always. This is simply not guaranteed.
I really need a process to continue to attach the location of the header to shut down the system and generate logs
with mod_php you will need ignore_user_abort() and with php-fpm it fastcgi_finish_requestβ() to guarantee the execution of the whole script.
source share