Determine my position in a queue table (Can I check if a browser session is still active?)

  Kiến thức lập trình

I am trying to make a waiting queue for an e-ticket system.
I have 2 tables.

  1. OrderSessions (in this table the active orders a stored)
  2. WaitingQueue (in this table I store the sessions if OrderSessions contains more than xx records).

In my SystemTable I set the maximum of active OrderSessions, for example 2
So if a users wants to buy an e-ticket, I check if there are more than 2 session active. If so, I write the GuidID (sessionID), StartTimeQueue (and some other values) in table WaitingQueue.

Every 10 seconds I check if there are still 2 records in OrderSessions and I check the position of this session in WaitingQueue (where EndTimeQueue=NULL).

If OrderSessions.recordcount < 2 and position in WaitingQueue is = 1 then I store EndTimeQueue in table WaitingQueue and I add a record to OrderSession with the Guid. And the actual order-screen is shown to the user.

This all works fine… 😉 The user who is at the 1st position in table WaitingQueue

My problem:
When it’s very busy with ordering tickets, the WaitingQueue contains a lot of records.
And very ofte a user closes its browser. But, the record still exists in table WaitingQueue.

My question:
Every active browser sessions “talks” to the server every 10 seconds. Is there a way the server can check if a session in the WaitingQueue is still active? Or is there any other way I can delete the record from the WaitingQueue when the user has terminated its browser?

LEAVE A COMMENT