PHP&会话:有什么方法可以禁用PHP会话锁定吗? [英] PHP & Sessions: Is there any way to disable PHP session locking?

查看:44
本文介绍了PHP&会话:有什么方法可以禁用PHP会话锁定吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用默认会话处理程序时,是否有任何方法可以禁用PHP中的会话锁定?

Is there any way to disable the session locking in PHP while using the default session handler?

还是至少有一种方法可以在调用session_write_close()之后重新启动会话?如果已将任何输出发送到浏览器,则session_start()不起作用.

Or is there at least a way to restart a session after calling session_write_close()? session_start() does not work if any output is already sent to the browser.

推荐答案

您不想禁用它...如果这样做,则可能会在登录到一个窗口时遇到各种奇怪的问题,被注销,然后进入不一致状态...锁定是有原因的...

You don't want to disable it... If you do, you'll potentially run into all sorts of weird issues where you login on one window, be logged out on another and then wind up in an inconsistent state... The locking is there for a reason...

相反,如果您知道不打算在该请求中写入会话,请尽早关闭会话.一旦启动它,即使在调用session_write_close之后,您也可以从中读取整个请求(除非重新启动它或执行其他一些特殊操作).因此,您要做的就是检查该请求以查看它是否为写请求,如果不是,则在打开请求后立即将其关闭.请注意,如果您稍后尝试写入会话(对于验证码或CSRF保护或其他功能),可能会产生一些不利影响,因此请谨慎使用...

Instead, close the session very early if you know you are not going to write to it in that request. Once you start it, you'll be able to read from it for the whole request (unless you re-start it, or do some other special things) even after you call session_write_close. So what you would do, is check the request to see if it's a write request, and if it's not, just close it right after opening it. Note that this may have some adverse affects if you later try writing to the session (For Captcha or CSRF protection or something else), so use with caution...

但是,除了尝试解决这个问题之外,我将努力要么缩短请求长度(以减少锁争用),要么为根本不需要会话的那些请求发出无cookie的请求...

But instead of trying to get around it, I would put my effort into either shortening the request lengths (to reduce lock contention), or making cookieless requests for those requests that don't need the session at all...

这篇关于PHP&会话:有什么方法可以禁用PHP会话锁定吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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