PHP instance: displays code accurately to the number of online users per second

Source: Internet
Author: User
? Phpsession_start (); $ dat_now1 = date ("H + I + s"); // Obtain the time $ p2 = explode ("+", $ dat_now1 ); $ dat_number1 = $ p2 [0] * 3600 + $ p2 [1] * 60 + $ p2 [2]; // Obtain the second if ($ online_time "") // last refresh time {$ dat

Session_start ();
$ Dat_now1 = date ('H I s'); // Obtain the time
$ P2 = explode ('', $ dat_now1 );
$ Dat_number1 = $ p2 [0] * 3600 $ p2 [1] * 60 $ p2 [2]; // second

If ($ online_time <> '') // The last refresh time
{$ Dat_h = substr ($ online_time, 11, 2 );
$ Dat_ I = substr ($ online_time, 14,2 );
$ Dat_s = substr ($ online_time, 17,2 );
$ Dat_number = $ dat_h * 3600 $ dat_ I * 60 $ dat_s;
}

$ Tmptime = $ dat_number1-$ dat_number; // Number of seconds between the last time and the present
If (session_is_registered (username) & ($ tmptime> 300) then wait ($ tmptime <0) // if less than 5 minutes
{
$ Online_time = date ('Y-m-d H: I: s ');
$ Str = 'replace lt_t_online set lt_username = '$ username', lt_lasttime = now ()'; // write it into the database
$ Res = mysql_query ($ str );
}
?>
The above files are automatically refreshed every minute
The following is the daemon process that runs once every 5 minutes:
$ Str = 'delete from lt_t_online where UNIX_TIMESTAMP (NOW ()-UNIX_TIMESTAMP (lt_lasttime)> 100 ';
Mysql_query ($ str );
?>

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.