Question

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'

Was it helpful?

Solution

You could use the date modified.

$last_modified = filemtime("thisfile.php");

OTHER TIPS

The file size isn't such a bad way.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top