Home >Backend Development >PHP Tutorial >Chat room technology-how to refresh when only new comments are made_PHP tutorial

Chat room technology-how to refresh when only new comments are made_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:24:441019browse

When actively refreshing, the program must constantly judge whether there is a new statement, and if not, repeat it.
Here I introduce a method similar to C language programming effect
//A time mark, because generally PHP scripts There is a time limit for execution
$delaytime=0;
//Loop
while(1)
{
//Determine whether there are new statements. My $filename here stores the total number of statements. , $last is the last message displayed
$message = file($filename);
$number = $message[0];
//Delay for 1 second
sleep(1 );
//The time mark increases
$delaytime++;
//If the time mark reaches the allowed script running time, exit the loop
if($delaytime > 25) break;
/ /If there is a new statement, exit the loop
if($number > $last) break;
}
//Process updates
... ...
This will not happen The page keeps refreshing, which is very annoying! ! !

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532099.htmlTechArticleWhen actively refreshing, the program must constantly determine whether there are new statements, and if not, repeat them. Here I Introducing a method similar to the effect of C language programming // A time mark, because...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn