A classic PHP statistics online user number of code, together learn to share.
<?php
/**
* Created by Phpstorm.
* User:jifei
* DATE:15/11/24
* time:20:58
*
* Millions of users per minute, real-time statistics the total number of online users in the last 15 minutes
*/
Class Onlineuser
{
"Online"; Key prefix
function __construct()
{
$this, new Redis();
}
/**
* Add new online users to the collection
*
* @param $uid
*/
function AddUser($uid)
{
$this,redis, Sadd($this,date(' Hi ')$uid );
}
/**
* Get the number of users online
*
* @param $start _min statistics start minutes hi format
* @param minutes of $end _min statistics end
*
* @return Mixed
*/
function Usernum($start _min$end _min)
{
The first parameter, and the key name of the set
$params[$this, $end _min;
Traverse all the minutes within the time interval and put into the parameters
($start _min$end _min$min+ +{
$params[$this, $min;
}
For all minutes of user's set up and save, performance than the direct calculation returned much faster, eliminating the data transfer
Call_user_func_array(redis"Sunionstore", $this,$params);
Delete temporary and set
Delete($params[0]) , Redis, $this
$num;
}
}
Date Published: 2016-07-30 511 met
Category: PHP Tags: php
PHP statistics number of online users