Home  >  Article  >  php教程  >  php获取当前在线人数的方法

php获取当前在线人数的方法

WBOY
WBOYOriginal
2016-06-21 08:49:131171browse

下面分享一种利用php实现简单的计算当前网站在线人数的方法,只是简单的通过计算访问者ip地址从而得出一个大致的结果,不能精确的计算当前在线人数,对精度要求过高的可参考本站文章:

php统计在线人数,精确的统计在线人数的办法

time())){
		array_push($temp,$entry[0].','.$entry[1].'n');//取出其他浏览者的信息,并去掉超时者,保存进$temp 
	}
}
array_push($temp,getenv('REMOTE_ADDR').','.(time()+($timeout))."\n");//更新浏览者的时间 
$users_online=count($temp);//计算在线人数
$entries=implode('',$temp);
//写入文件 
$fp=fopen($online_log,'w');
flock($fp,LOCK_EX);//注意 flock() 不能在NFS以及其他的一些网络文件系统中正常工作 
fputs($fp,$entries);
flock($fp,LOCK_UN);
fclose($fp);
echo '当前有'.$users_online.'人在线';



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