Sockets: send data to server, server waits until disconnect to insert in database

I want to send data to the server using sockets, so I can update it very frequently.
But I don’t want the server to do a ‘database update’ query every time it received a message from the socket.

One use case is for keeping track of the last watched time on a video.

Let’s say we have a video of 60 seconds.
Each second it’s sending a message using the client side socket component. This message contains the currently watched time.
User watches 11 seconds. So at second 11, it sends this data to the server.

The server should now keep this data (store it in a server side session var?)

Until the user disconnects from the socket.

So I set this up in the ‘disconnect’ socket

However this ‘disconnect’ socket doesn’t seem to have access to that session variable:


“update data does not contain any values to update”

How can I accomplish this?