查了下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_write_close函数,作用是Write session data and end session,也就是写session的数据,同时关闭这个session。因此,我们可以在用完session之后,调用这个函数关闭session 文件即可接触锁定。一般,session是用来记录用户身份信息的,以便PHP进行身份认证,因此完全可以将session的读写放在页面刚开始执行的时 候,在执行完以后,马上调用session_write_close函数即可。