PHP Sessions - Locking and Sharing questions

后端 未结 2 1995
傲寒
傲寒 2021-01-13 14:53

I would like to know if it is possible to read $_SESSION attributes without locking it.
Currently, session_start() locks SESSION, that means other PHP proce

2条回答
  •  佛祖请我去吃肉
    2021-01-13 15:24

    Interesting question!

    session_write_close() is not exactly what you're asking for but it should help speed up the process:

    Session data is usually stored after your script terminated without the need to call session_write_close(), but as session data is locked to prevent concurrent writes only one script may operate on a session at any time. When using framesets together with sessions you will experience the frames loading one by one due to this locking. You can reduce the time needed to load all the frames by ending the session as soon as all changes to session variables are done.

    A script that needs only read-only access could start the session, copy the session variables into another array and apply session_write_close(). It won't be a fully read-only solution - it could be that you'd need to build your own session handler for that - but it should be a big step forward.

    Update: I just found an interesting issue from 2001 in the PHP 4 tracker that seems to introduce a patch enabling read only sessions - it doesn't seem to have made it to the official releases, though, at least not according to the documentation! Maybe it's worth digging further or reopening the Ticket for PHP 5.

提交回复
热议问题