Search code examples
mysqlcountingtimedelay

Time-Delayed MySQL "Update" for More Realistic Tally of Online Video Views


I'm creating a video embed page for a real estate site, where a user can go to watch a video tour of a given home. There is no other reason to visit that particular page, so I figured that I could use a simple MySQL Update to a "video view tally" column for that homes's row, which will update views=views+1 each time the page is loaded.

That's easy enough, but I want to give as realistic a "view" count as possible, so I'm trying to come up with a way to have that view tallied ONLY once the page has been loaded for a set number of seconds (say, 30).

Any thoughts on a good way to handle the timing aspect? I'd like to avoid javascript, if possible, but I'm open to if it it's handled simply enough.


Solution

  • Unfortunately the only way you will ever know if the page is still active is to have a client-side technology (like JavaScript) tell you that it is.

    You can add a "counter" page that isn't meant to be viewed directly, but instead is accessed via JavaScript after a 30 second page timer has expired. The act of JavaScript accessing that page will trigger the counter logic.