Chat room technology-how to refresh the PHP Tutorial only when new speeches are made

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.