Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5945457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:41:03+00:00 2026-05-22T16:41:03+00:00

I’m making a user count script with PHP and jquery and I would like

  • 0

I’m making a user count script with PHP and jquery and I would like to have a way of telling if the user is inactive.

$.mousemove(function(){
//get php to update time on user
});

but how should I set it so that it wouldn’t update every time it moved but once every 1 sec? Like this?

$.mousemove(function(){
//get php to update time on user
$.delay(1000);    
});

then I will also add a key up function with the same thing so that i can also tell if keyboard is active or not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:41:04+00:00Added an answer on May 22, 2026 at 4:41 pm

    Hopefully this is self explanatory, and hopefully it works! This notifies the server immediately when the user moves the mouse, assuming the server hasn’t been notified in over a second, AND periodically.

    We schedule activityNotification() to run every second (using something like jQuery timer or the setInterval(func, time) function), in order to handle the following timeline as responsively as possible:

    • 0 ms: user moves mouse, server notified
      immediately
    • 657 ms: user presses key,
      but too early to notify server of
      activity
    • 1000 ms:
      activityNotification() runs as
      scheduled, sees that we have
      activity we have not notified the
      server about, notifies server
    • 2000 ms: activityNotification() runs as
      scheduled, but nothing to inform server about
    • 2124 ms: user moves mouse, server notified immediately as it’s been 1.124 seconds since the server was last notified

    Code:

    //Track the last activity you saw
    var lastActivity = 0;
    
    //Remember the last time you told the server about it
    var lastNotified = 0;
    
    //Determines how frequently we notify the server of activity (in milliseconds)
    var INTERVAL = 1000;
    
    function rememberActivity() {
        lastActivity = new Date().getTime();
    
        activityNotification();
    }
    
    function activityNotification() {
        if(lastActivity > lastNotified + INTERVAL) {
            //Notify the server
            /* ... $.ajax(); ... */
    
            //Remember when we last notified the server
            lastNotified = new Date().getTime();
        }
    }
    
    setInterval('activityNotification()', INTERVAL);
    
    $.mousemove(function() {
        //Remember when we last saw mouse movement
        rememberActivity();
    });
    
    $.keyup(function() {
        //Remember when we last saw keyboard activity
        rememberActivity();
    });
    

    And remember, not all users will have JavaScript enabled, and this will cause serious battery drain on mobile devices.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.