会话过期时,PHP运行脚本 [英] PHP run a script when a session expires

查看:70
本文介绍了会话过期时,PHP运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个购物车应用程序,其中包含数量为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_divisorsession.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运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆