views:

42

answers:

2

Hi guys,

I have recently started programming in PHP.

I am building a cart in PHP. I have my products locked in cart when someone adds it to their cart.

I need to unlock those products when the specific user gets logoff or session expires.

How can i call something like session_onend function as in asp/asp.net to unlock/release those locked products?

+1  A: 

You can write a custom session handler and implement your own garbage collector.
http://www.php.net/manual/en/function.session-set-save-handler.php
But I would advise against such a locking. It will mess your stock. As only a few people will buy their cart load in real.

Col. Shrapnel
+1 for the custom session handling. Not sure about your stock remark though. You can't know what type of site OP is aiming for. Might very well suit OP's needs.
fireeyedboy
Thnx for suggestion of not locking cart items. It was useful. Rest abt the session handler function does it works when the session_timeout occurs or when the user close the browser
KoolKabin
@Kool it's timeout based. Server has no way to know if client closed their browser, as there is no persistent connection between browser and server.
Col. Shrapnel
can u tell me the logic how does the php function gets fired when timeout occurs
KoolKabin
A: 

Why not consume the product from stock when the order is actually placed. Hold the product until the user fills out the correct info for billing, then reduce inventory when all goes correctly?

Kris.Mitchell
this can be good option
KoolKabin
What if I want to find how many and who are currently visiting the site
KoolKabin
I mean if we are talking about a "holding" area for orders that are being built, you would be able to see what user was in the "holding" table and what products they had in their cart. You could then write a report (or something) that could be run to see your current commitment.You see this a lot with shopping carts where people can shop, with a temp cart. For example if the session ends or a timeout period happens you can compare against a time in the database. If the time is overdue, do something with the abandoned rows.
Kris.Mitchell