PHP的Session阻塞问题探讨
2013-08-09 17:37
330 查看
使用session过程中,在开启session后,同一浏览器,执行同一程序,不同页面会被锁。不同浏览器不会出现这种情况。 疑问:是不是session_start导致了阻塞?
于是,我写了几个页面测试了一下,发现是session导致了阻塞,而其他两种情况不会造成阻塞。 查了下PHP的Bug列表,发现有人提出了这个问题:
Description:
------------
Calling session_start() appears to wait until other scripts have exited
that are using the same session. My guess is the 1st request locks the
session file for exclusive use, and the second request blocks until it
can open it.
PHP官方的回复是:
Thank you for taking the time to write to us, but this is not a bug.This is expected, the session file is locked to avoid corruption.
结合了PHP的Session机制,找到了阻塞的原因。由于PHP的Session信息是写入文件的,1个客户端占有1个session文件。因此,当 session_start被调用的时候,该文件是被锁住的,而且是以读写模式锁住的(因为程序中可能要修改session的值),这样,第2次调用 session_start的时候就被阻塞了。 最简解决方法: 查了PHP的手册,发现一个session_write_close函数,作用是Write session data and end session,也就是写session的数据,同时关闭这个session。因此,我们可以在用完session之后,调用这个函数关闭session 文件即可解除锁定。一般,session是用来记录用户身份信息的,以便PHP进行身份认证,因此完全可以将session的读写放在页面刚开始执行的时 候,在执行完以后,马上调用session_write_close函数即可。
相关文章推荐
- PHP的Session阻塞问题探讨
- php session读写锁引起的脚本阻塞问题
- PHP中Session引起的脚本阻塞问题解决办法
- PHP中Session引起的脚本阻塞问题解决办法
- PHP中Session引起的脚本阻塞问题解决办法
- PHP中Session引起的脚本阻塞问题解决办法
- PHP Session并发操作阻塞问题
- PHP session阻塞页面的问题
- php的session阻塞问题
- PHP session文件独占锁引起阻塞问题解决方法
- PHP session文件独占锁引起阻塞问题解决方法
- php session阻塞
- php中的session问题
- PHP中Session可能会引起并发问题
- 探讨php中error_log函数输出内容的原子性问题
- php session跨域问题研究学习
- php中session_start()相关问题分析与解决办法
- 解决php中Cannot send session cache limiter 的问题的方法
- 探讨PHP引用&符号的一些注意问题
- 关于PHP集成环境session_start出现错误的问题