Welcome Guest, Not a member yet? Register   Sign In
Detect when a session times out and execute a function
#1

[eluser]funkmyer[/eluser]
Is this possible? If so, has anyone had any experience with this? Basically, I have a shopping cart that decrements stock counts as items are entered into their basket. I have a function that fires when someone "empties" their basket that will free those stock levels back up.

If someone puts items in a cart and then goes out for the day, the session will expire and lose the cart contents, thus stock levels will now be incorrect. Can anyone think of an intelligent way to handle this situation without running an interval'd cron job.

Thanks a bunch, and long live CI!

Smile
#2

[eluser]Seppo[/eluser]
You can store the last session activity and once in a while (once a day probably will be enough) clean up the baskets that weren't used.
Probably you will need a cron job to not run it manually.
#3

[eluser]wiredesignz[/eluser]
In the past I have used a table to store cart quantities and session id, along with a session table storing last activity and session id.

Each new visitor to the site triggers a clean up of expired sessions and restores stock counts.
#4

[eluser]funkmyer[/eluser]
Thanks for sharing your thoughts guys, that was helpful.

Best - funkmyer
#5

[eluser]funkmyer[/eluser]
[quote author="wiredesignz" date="1206116803"]Each new visitor to the site triggers a clean up of expired sessions and restores stock counts.[/quote]

How are you able to detect each time a new session is created? Is there some of event fired or a callback function avaiable with CI's session handling ?

Thanks.
#6

[eluser]sandwormusmc[/eluser]
Not sure if this would work for you, but how about an AJAX call to a CI function that checks user's last activity against current time? If it's past a certain threshold, have it destroy the session, clear your inventory, and spit back javascript code to redirect that user to a "sorry, your session expired" page ... including JS code to do that in the header or footer wouldn't be too hard, especially using MooTools another JS framework of your choice.

If you need an example, let me know and I can throw something together ...
#7

[eluser]Tom Glover[/eluser]
If you are using CI sessions the clean up is called is automated, all you have to do is call the CI session library when needed.

The session library automates, creation, update and deletion, read the manual for more information.
#8

[eluser]sandwormusmc[/eluser]
[quote author="WackyWebs.net" date="1206135280"]If you are using CI sessions the clean up is called is automated, all you have to do is call the CI session library when needed.

The session library automates, creation, update and deletion, read the manual for more information.[/quote]

Right, for session data ... but his stock levels aren't session data, so it requires a bit of extra work.
#9

[eluser]funkmyer[/eluser]
precisely -- I'm aware that all the session handling is automated so I'm trying to find a hook/event to tie into when the session garbage collection runs. Thanks guys, all your feedback and thoughts are greatly appreciated!

I'm going to do something along the lines of sandworm's recommendation, so I guess my last lingering question is if anyone knows of any hooks/events/triggers etc.. for the automated session garbage collection to signal one of my own functions to run some additional operations. Although thinking about it, that possibly wouldn't work anyways as by the time I got the "signal" that session garbage collection has started, and the data I need may already be gone...der

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB