问题描述
我有一个购物车应用程序,其中包含数量为1的独特商品-当用户将一个商品放在购物篮中时,我需要减少库存数量,以避免其他人购买它.问题是,如果他们放弃购物车放弃购物,我需要将其放回库存.
I have a cart application with unique items with qty 1 - I need to deplete the stock qty when a user puts one in the basket to avoid someone else buying it. Problem is, that if they abandon the cart without buying I need to put the item back in stock.
当购物车会话结束时,是否可以补充库存?即运行脚本来替换库存.
Is there a way I can replenish the stock when the cart session expires? ie run a script to replace the stock.
推荐答案
您可以使用session_set_save_handler
创建自定义会话处理类.当执行此操作时,您可以决定在调用垃圾收集器时或在会话销毁时需要运行的其他操作.如果您决定使用垃圾收集器,请确保您还知道session.gc_divisor
和session.gc_probability
的值,并了解它们的作用(这些设置了垃圾收集器将运行的可能性).
You can use session_set_save_handler
to create a custom session-handling class.When you do this, you can decide other actions that need to run either when the garbage collector is called or at session destroy. If you decide to work with the garbage collector, ensure that you also know the values for session.gc_divisor
and session.gc_probability
and also understand what they do (these set the probability that the garbage collector will run).
这篇关于会话过期时,PHP运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!