This is tricky because there is buffering behavior between the web server and your browser. Your script might be outputting stuff like '5% done.......6%done...etc' but these updates will only get sent from webserver to browser at unpredictable intervals.
I have managed before to write a php script that the user visits via web browser which 'forks off' another process and then returns immediately. Let's assume for a moment that you have some time-consuming script called long_script.php which you want to run. Create another script called script_launch.php which has this code:
$start_cmd = "php long_script.php > /dev/null & echo \$!";
$output = array(); // will contain an array of output lines from the exec command
$result = null; // will contain the success/failure code returned by the OS. Will be zero for a valid command, non-zero otherwise
$return = exec($start_cmd, $output, $result); // $return will contain the last line from the result of the command which should be the PID of the process we have spawned
if ($result) {
die('We were unable to fork off the long process:' . print_r($output));
}
echo 'Process forked! Your pid is ' . $return . '<br>';
echo 'output:<br>';
echo nl2br(print_r($output, true));
With a bit of modification, this script could be altered to redirect to another php page which repeatedly checks to see if the other script is finished. It could simply refresh itself using a META tag.
The trick would be to alter long_script.php so that it provides some kind of indicator about its progress. Ideally, it would use a threadsafe database like MySQL so that the two scripts, if running at exactly the same time, wouldn't both try to access the same file thereby producing an error or race conditions or some other concurrent execution nastiness.