php - JQUERY poll MYSQL db only if user is active -
i'm building interactive page chatbox , list of items appear.
i intend update both of them every 30 seconds using jquery's .post() function, realize many users keep webpages opened in tabs 24 hours day, creating heavy load on server.
in order prevent , optimize ressources, database polling executed every 30 seconds if user active on page; in passive cases, 5 minutes polling.
how can achieve this? (i'm using php , mysql)
maybe try detect cursor position changing.
- on page load start setinterval method send request php
- add adittional setinterval check if user cursor moving
- if not wait time , clear 1 interval.
- if yes allow interval works normally.
i'm not sure how work cursor position checking method if user go other tab. prepare test (only js)
edit:
w3c start working on page visibility
document attribute: http://www.w3.org/tr/page-visibility/
but better solution. on answer: https://stackoverflow.com/a/1060034/390747
Comments
Post a Comment