简体   繁体   English

我如何告诉php GC永不过期或删除会话

[英]How can i tell php GC to never expire or delete a session

I have tried a lot of solutions to prevent sessions expiring, but no onw has worked, the last solution was to set 我尝试了很多解决方案来防止会话过期,但没有成功,最后一个解决方案是设置

session.gc_maxlifetime = 0
session.gc_probability = 0

But it doesnt work, any other idea to prevent the session expiring? 但这不起作用,还有其他防止会话过期的想法吗?

It is a bad idea to do that, but to answer the question ... you can override the default session handler with a custom one and have it ignore the GC calls: 这样做是一个坏主意,但是要回答这个问题……您可以使用自定义会话处理程序覆盖默认会话处理程序,并使其忽略GC调用:

class NoGCSessionHandler extends SessionHandler {

    public function gc($maxlifetime)
    {
        return true;
    }

}

session_set_save_handler(new NoGCSessionHandler());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM