Webbrowsers don't have a permanent connection to your webserver.
It is therefore not possible to detect when a user closes his browser or loses his connection in some way.
(Maybe with javascript, but that is not reliable enough).
So, the only way to detect that a user has left is by a time-out.
A brainstorm about a possible solution:
Every time the user does anything with his session/transaction,
you reset a "timer" for the selected items. This can be a datetime value in a mysql table that keeps track of when the items were last referenced by the client.
When other clients want to access the same items, you check if the "last referenced" time for that item was more than one our ago.
If not, the item is not available. If yes, the item is available.
If the item is available, you can delete it from the table and create a new entry for the new client. (or update the record)