PHP Session expire/close detection
Posted on 2006-10-29
I need a way to detect session close/expire and run a task when this happens. Here's the the situation:
I have a custom shopping cart. When people add x of an item to the cart, the system "locks" x items. Meaning it takes them temporarly from the inventory. After 20 min or inactivity it will unlock the items. Each time the cart loads it will attempt to relock the items reseting the time.
This all works perfectly. My problem is this:
Say someone puts 10 items in the cart. 10 items are locked. Now the user closes the browser. The cart session goes away, but the 10 items are still locked. They will remain locked for 20 min. I would like to just remove the locks when this happens. But i don't know how to detect this.
I need a way to be able to tell when my $_SESSION["order_id"] is closed or expired. And when it does it gets even more complex. In order to remove the locks, i need to know what the order_id was.
So in summary, i need to know when $_SESSION["order_id"] goes away, and what it was so i can then delete the locks associated with the order.
Of course if you have another idea of how to do this, i'm all ears.