会话结束时运行脚本 [英] Run script when session ends

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

问题描述

我正在研究在用户会话结束时如何运行脚本或函数,以便可以删除可能需要的临时文件。

I am looking at how I can run a script or function when a user's session ends so that I can delete temporary files which may be required.

我已经搜索了在SO周围找到解决方案,并遇到 ,但是我发现我的想法还不够深入,我发现有关GC的PHP文档令人困惑(从我从该文档中了解的内容来看,这并不是我真正需要的)。

I have searched around SO to find a solution to this problem and came across this but I find I am a little out of my depth and I find the PHP documentation regarding GC to be confusing (and from what I understand from the documentation - it is not really what I need).

我在 session_set_save_handler 并提出:

I looked at the page on session_set_save_handler and came up with this:

session_set_save_handler( '', '', '', '', 'deleteDocs');
function deleteDocs()
{
    rmdir('user/' . rawurlencode($_SESSION['data']['user']['details']['email']) . '/temp');
}

但是,此功能根本无法运行。坦白地说,我感觉不知道自己在做什么。

However, this function does not run at all. Frankly, with this, I feel like I do not know what I am really doing.

我尝试使用GC并查看了 session.gc_divisor session.gc_probability 但我还是无法编辑php.ini。

I tried using GC and looked at session.gc_divisor and session.gc_probability but I cannot edit php.ini anyway.

这可以实现吗?我应该使用cron作业-如果是这样,如何检查会话是否完成?

Can this be achieved. Should I be using a cron job - if so, how can I check that sessions are finished?

推荐答案


我应该使用cron作业-如果是这样,我如何检查会话是否完成?

Should I be using a cron job - if so, how can I check that sessions are finished?

是。您基于文件的上次修改时间来执行此操作(在您的情况下,该文件为目录)。如果它已超过最大会话期限,则删除目录。

Yes. You do this based on the file last modification time (in your case the file is a directory). If it's older than the maximum session age, delete the directory.

您可以使用 查找 维基百科 命令。

您可以在PHP文件夹中找到一个示例脚本,另请参阅从自定义集中删除旧的会话文件会话文件夹?清理php会话文件

You find an example script in your PHP folder, see as well Deleting old session files from custom set session folder? and cleanup php session files.

这篇关于会话结束时运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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