PHP statistics number of online users

Source: Internet
Author: User

A classic PHP statistics online user number of code, together learn to share.

  1. <?php
  2. /**
  3. * Created by Phpstorm.
  4. * User:jifei
  5. * DATE:15/11/24
  6. * time:20:58
  7. *
  8. * Millions of users per minute, real-time statistics the total number of online users in the last 15 minutes
  9. */
  10. Class Onlineuser
  11. {
  12.     "Online";  Key prefix 
  13.     function __construct() 
  14.     {
  15.         $this, new Redis();    
  16.     }
  17.     /**
  18.     * Add new online users to the collection
  19.     *
  20.     * @param $uid
  21.     */
  22.     function AddUser($uid)  
  23.     {
  24.         $this,redis, Sadd($this,date(' Hi ')$uid );
  25.     }
  26.     /**
  27.     * Get the number of users online
  28.     *
  29.     * @param $start _min  statistics start minutes hi format
  30.     * @param    minutes of $end _min statistics end
  31.     *
  32.     * @return Mixed
  33.     */
  34.     function Usernum($start _min$end _min)   
  35.     {
  36.         The first parameter, and the key name of the set
  37.         $params[$this, $end _min;    
  38.         Traverse all the minutes within the time interval and put into the parameters
  39.         ($start _min$end _min$min+ +{    
  40.             $params[$this, $min;    
  41.         }
  42.         For all minutes of user's set up and save, performance than the direct calculation returned much faster, eliminating the data transfer
  43.         Call_user_func_array(redis"Sunionstore", $this,$params);  
  44.         Delete temporary and set
  45.         Delete($params[0])      , Redis, $this 
  46.         $num;
  47.     }
  48. }

Date Published: 2016-07-30 511 met

Category: PHP Tags: php

PHP statistics number of online users

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.