too long

I have a heavy loop that takes some time to be finished (usually around 5 minutes).

It doesn't really require anything from the user except for actually running it.

What happens in PHP if the user closes the browser while it still waits for a response from the server?

And if as I'm worried - it stops the script from being executed (leading partial execution) - is it possible to avoid it and make PHP finish what it started at all times?

ignore user abort and set_time_limit for the execution time of the script itself as functions or as a ini setting.

you can ensure using log file in following way

<?php
    for($i=1;$i<300000000;$i++)
    {
         /*you heavy code goes here*/
    }
    error_log($i. "counts occure",0);
    echo $i;
?>