PHP Session expire event

前端 未结 3 436
暖寄归人
暖寄归人 2020-12-11 10:10

I am trying to make some changes to an opensource project. I want to keep track of when users log in and log out. Right now I change their login status in db when they logi

3条回答
  •  不知归路
    2020-12-11 10:51

    I did something really nasty once. Every time a session was "updated" by a page refresh / fetch / etc., I updated a timestamp on a DB row. A second daemon polled the DB every 10 minutes and performed "clean-up" operations.

    You won't find any native PHP facilities to achieve your goal. Session timeout doesn't run in the background. You won't even know if a session is timed out, unless a timed out session attempts another access. At this point, nearly impossible to trap, you can make your determination and handle it appropriately.

    I'd recommend a queue & poll architecture for this problem. It's easy and will definitely work. Add memcached if you have concerns about transaction performance.

提交回复
热议问题