Chat room technology-how to refresh only when new speeches are made. During the active refresh process, the program will constantly judge whether there are new statements. if there are no new statements, repeat them. here I will introduce a method similar to the C programming effect and a time mark, when the program is actively refreshing, it will constantly judge whether there are any new statements. if not, it will repeat them,
Here I will introduce a method similar to the C programming effect.
// A time mark, because the execution of php scripts has a time limit.
$ Delaytime = 0;
// Loop
While (1)
{
// Determine whether a new speech exists. here, $ filename stores the total number of speeches, and $ last is the one shown last time.
$ Message = file ($ filename );
$ Number = $ message [0];
// Delay 1 second
Sleep (1 );
// The time Mark is added.
$ Delaytime ++;
// Exit the loop if the time Mark is approaching the allowed script running time
If ($ delaytime> 25) break;
// Exit the loop if a new statement exists.
If ($ number> $ last) break;
}
// Process updates
......
In this way, the page will not be refreshed constantly, which is very annoying !!!
Compile, here I will introduce a method similar to the C programming effect // A time mark, because...