How about...
We have to assume that there is some way to determine the total job (100%) and the point that the php script is at (the % done status), so if it's reading/parsing a text file, you could have the parsing function start by writing the total line count to a db or text file. Then it can also write which line number it's on to that same file every 5 seconds. The js ajax function calls to that text file to get the total and the point it is on. When the php text parser is done, it destroys the status file to prevent it from taking up server space, file name conflicts, etc.
Example:
First, the (jquery) ajax function POSTs to the server:
$.post("parser.php", { file: "somefile.txt"} );
//I admit, I'm not sure if this is how a file would be posted with ajax
Next, the php pulls the file and starts the parser function:
$tmpName = $_FILES['userfile']['tmp_name'];
$fileName = $_FILES['userfile']['name'];
//Turn the file into an array, so that you can use the array count for status:
$content = file($tmpName);
// Get the array count as the total, as it equals the line count:
$total = count($content);
//Write the filesize to a unique "total" txt file:
$total_file = fopen($fileName."-total.txt", 'x');
fwrite($total_file, $total);
fclose($total_file);
//Pass the Array to the parser function:
parser($content, $fileName);
//Kill the file when the function is done:
unlink($fileName);
function parser ($file_array, $filename) {
//creates the status file and then closes it, to ensure that it
//exists for the loop but gets overwritten each time
$status_file = fopen($filename."-status.txt", 'x');
fclose($status_file);
foreach($file_array as $position => $data) {
//Do your parsing here //
.............
//reopen status file and wipe out what is in it already:
$status_file = fopen($filename."-status.txt", 'w');
fwrite($status_file, $position);
fclose($status_file);
}
}
So since the status and total file share the hopefully unique name of the uploaded file, the ajax function knows where to look. It can do this:
total = $.get("somefile-total.txt");
current = $.get("somefile-status.txt");
status = current/total;