If visitors use your website as normal website without Socket.IO, then you might rethink the whole approach of tracking. In order to do it efficiently without any work on front-end that could lead to performance issues think of this approach:
I would choose MongoDB (feel free to use redis with similar approach) with smart expire indexing (this will create expire document if Now - timestamp will be longer then 10 seconds)
db.views.ensureIndex({ timestamp: 1 }, { expireAfterSeconds: 10 })
And would create index for product for fast counting
db.views.ensureIndex({ product: 1 })
You can create documents, with this structure:
_id: '(int)userId'
product: '(int)productId'
timestamp: new Date() (have expire index on this one.)
When user comes to view Product, PHP would record userId (_id), productId (product) and present datetime (timestamp). Use update with upsert flag in order to insert in case if document not found.
This will make sure that one user can view only one product at the moment, and will efficiently expire records as well as switch to another products if user navigated so.
db.views.count({ product: 42 })
- would output present count of users viewing product 42.