Check if PHP session_id is in use

后端 未结 4 1557
既然无缘
既然无缘 2021-01-02 23:25

I am building a web-app that users can upload certain files and work on them through the web-app interface. I need to store these files for the length of a users session. I

4条回答
  •  醉酒成梦
    2021-01-03 00:20

    The problem you have is basically the same problem (on a less complex level) that occurs when you have got a custom session file directory. You need to clean it up yourself as well. The process is also known as garbage collection.

    This is normally done by having a janitor job running on the server side that checks for outdated session files, or in your example, for outdated session directories (this can be a cron job).

    This is how it works:

    Most file-systems store the creation and last access date of a file. So if a session times out it has not been used any longer for X hours. So you can safely assume that if a session file has not been accessed within the last X hours that the session is dead and all files "older" than this amount of time can be safely deleted.

    Job done. For your directory you might want to add a file inside you'd like to use as a testfile to track access time.

    The php manual has some examples of that: http://www.php.net/manual/en/session.configuration.php#ini.session.save-path (look for the mod_files.sh script)

提交回复
热议问题