聊天室技术-如何在只有新发言时才刷新
在主动刷新时,程序要不停的判断是否有新的发言,如果没有则重复,
这里我介绍一种类似 C 语言编程效果的方法
//一个时间标记,因为一般 php 脚本执行有时间限制
$delaytime=0;
//循环
while(1)
{
//判断是否有新的发言,我这里 $filename 存放的是发言总数,$last是上次已经显示的的发言
$message = file($filename);
$number = $message[0];
//延迟1秒钟
sleep(1);
//时间标记增加
$delaytime++;
//如果时间标记快到允许的脚本运行时间则退出循环
if($delaytime > 25) break;
//如果有新的发言则退出循环
if($number > $last) break;
}
//处理更新
... ...
这样就不会发生页面不停刷新,非常烦人的情况了!!!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.