search
Homephp教程php手册聊天室技术-如何在只有新发言时才刷新

聊天室技术-如何在只有新发言时才刷新

Jun 13, 2016 am 10:24 AM
judgmentrefreshonlyexisttechnologyhourhaveofprogramchatroomwant

在主动刷新时,程序要不停的判断是否有新的发言,如果没有则重复,
这里我介绍一种类似 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;
}
//处理更新
... ...
这样就不会发生页面不停刷新,非常烦人的情况了!!!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.