} $start = gettimeofday(); while (1) { // if the file size of chatroom.xml is changed, that means new message has been added if ($xmlh->fileExist()) { // if data size is changed, // stop running this while loop to send messages to user if ($_POST["datasize"] != filesize("chatroom.xml")) { break; } } // clear the internal cache of file system functions from php clearstatcache(); // we are not going to run the loop for more than 30 seconds $time = gettimeofday(); if ($time["sec"] - $start["sec"] > 30) { break; } // stop running the while loop for a second sleep(1); } $output = ""; // output the content of chatroom.xml as XML message if ($xmlh->fileExist()) { // open the existing XML file $xmlh->openFile(); // get all the elements in the XML file $output = $xmlh->dumpToString(); } // print the XML output print $output;