views:

133

answers:

2

Lets say I have a chat program that every time someone sends a message, a globalfile is locked and written to. The receiving client has a pending xmlhttp request that is waiting to return with the newly updated file using this construct:

while (!hasNewdata())
{    sleep 3;    }
print "$thenewdata";
sub hasNewData()
{
     # determine if global file has been appended to.
}

Would sending the file size to the client and then back to the server in the next poll request be a good method of doing this, as we can now check if the file size is different from what has already been sent back to the client so we know there is new data. Or would sending the file offset back and forth be a better approach so it knows where in the file to check for new data? Or a different method completely, something other than using a global 'chat' file?

What are general methods of determining 'new data available'

+4  A: 

You could use the date modified.

$last_modified = filemtime("thisfile.php");
Gazler
This is probably the better method if it's possible that your file size might remain the same while the data within changes.
Adam Bellaire
A: 

The file size isn't such a bad way.

Browsers might well already be tagging "if-modified-since" headers to the requests.

Will