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.
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).
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.
I tried using GC and looked at session.gc_divisor
and session.gc_probability
but I cannot edit php.ini anyway.
Can this be achieved. Should I be using a cron job - if so, how can I check that sessions are finished?