I didn't try this, but perhaps you can use a JS library such as Prototype to determine the length of the output, then compare it to the length of the last response and then act accordingly by cutting the string at the proper position.
Untested example:
var lastLength;
Ajax.Request('/tail.php', {
onSuccess: function(data){
/* this is our callback and data.responseText will contain the raw response from the server */
var curLength=String(data.responseText).length;
if(curLength>lastLength) {
$('myDiv').insert(data.responseText.substr(lastLength)); // append the new part of the string to a DIV with id 'myDiv'
lastLength=curLength;
}
}
});
If that solution for some reason is not satisfactory or leads to issues, you could try to have tail.php send more than just raw data. Instead, JSON could be used to include the byte count along with the data.
Assuming that
$tailOutput
contains the latest output, using
echo json_encode(array(
'tailOutput' => substr($tailOutput, $_REQUEST['tailLength']),
'curLength' => strlen($tailOutput)
));
to send the data back to the client, now including the last length information, and then adapting the JS code accordingly.
var lastLength;
Ajax.Request('/tail.php', {
parameters: {
tailLength: lastLength
},
onSuccess: function(data){
var obj=data.responseText.evalJSON(); //convert to json object
$('myDiv').insert(obj.tailOutput);
lastLength=obj.curLength;
}
}
});